Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jallah_88
Starting Member
12 Posts |
Posted - 2011-02-10 : 04:49:30
|
HiI'm trying to export a sql file to a csv file using following code:DECLARE @ExportCsv varchar(8000)SET @ExportCsv = 'bcp SC2835128..testing out E:\Martin.Christiansen\FirewallRegler.csv -c -t, -T -S' + convert(varchar,@@ServerName)PRINT @ExportCsvEXEC master..xp_cmdshell @ExportcsvWhen i try to execute this with inside ssms it gives me following error:SQLState = 37000, NativeError = 4060Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot open database "SC2835128" requested by the login. The login failed.SQLState = 28000, NativeError = 18456Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'NT AUTHORITY\SYSTEM'.NULLWhat is wrong? |
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-02-10 : 05:04:44
|
You are specifying the server name in the -T switch so there is no need for this to be in the database name (unless it's a linked server? is SC2835128 a linked server name?). Try this:SET @ExportCsv = 'bcp testing out E:\Martin.Christiansen\FirewallRegler.csv -c -t, -T -S ' + convert(varchar,@@ServerName)- LumbagoMy blog-> http://thefirstsql.com/2011/02/07/regular-expressions-advanced-string-matching-and-new-split-function-sql-server-2008-r2/ |
|
|
jallah_88
Starting Member
12 Posts |
Posted - 2011-02-10 : 05:14:07
|
Wow thanks, didnt know that. But now i get this error instead, which i really dont understand as testing is a functioning permanent table in my db?SQLState = S0002, NativeError = 208Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid object name 'testing'.NULLEDIT: fixed it. I must have slept when i read the many tutorials around the web. Working bcp is'bcp Monitor..testing out E:\Martin.Christiansen\FirewallRegler.csv -c -t, -T -S' + convert(varchar,@@ServerName)Of course i needed to specify the db to connect to |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-02-10 : 05:26:01
|
Excellent...I should of course thought of this as well, but my excuse is that I don't use bcp very much - LumbagoMy blog-> http://thefirstsql.com/2011/02/07/regular-expressions-advanced-string-matching-and-new-split-function-sql-server-2008-r2/ |
|
|
|
|
|
|
|