Click here to Skip to main content
15,896,111 members
Home / Discussions / Database
   

Database

 
GeneralRe: checking the type Pin
GuyThiebaut14-Feb-08 22:07
professionalGuyThiebaut14-Feb-08 22:07 
GeneralIs there a way to extract a value/result when you exec a sql string Pin
littleGreenDude14-Feb-08 9:08
littleGreenDude14-Feb-08 9:08 
GeneralRe: Is there a way to extract a value/result when you exec a sql string Pin
Christian Graus14-Feb-08 13:12
protectorChristian Graus14-Feb-08 13:12 
GeneralRe: Is there a way to extract a value/result when you exec a sql string Pin
andyharman14-Feb-08 21:54
professionalandyharman14-Feb-08 21:54 
GeneralBCPutility - Unable to open BCP host data-file Pin
#realJSOP14-Feb-08 6:34
professional#realJSOP14-Feb-08 6:34 
GeneralRe: BCPutility - Unable to open BCP host data-file Pin
Mike Dimmick14-Feb-08 12:44
Mike Dimmick14-Feb-08 12:44 
GeneralRe: BCPutility - Unable to open BCP host data-file Pin
#realJSOP16-Feb-08 0:24
professional#realJSOP16-Feb-08 0:24 
GeneralUsing xp_cmdshell [SOLVED] Pin
#realJSOP14-Feb-08 4:53
professional#realJSOP14-Feb-08 4:53 
I want to use xp_cmdshell to export the contents of a table to an xml file. Here's the sql I'm trying to use:

use MyDatabase

declare @dtStart datetime;
declare @dtEnd datetime;
declare @publisher varchar(50);
declare @outpath varchar(255);
declare @sql varchar(512);
declare @params varchar(512);

set @publisher = 'SomePublisher';
set @dtStart = '2008-01-01 00:00:00.000';
set @dtEnd   = '2008-01-01 11:59:59.999';

set @sql     = 'select * from MyDatabase.dbo.downloads where endtimestamp between ''' +
               Convert(varchar(50), @dtStart, 121) + ''' and ''' + 
               Convert(varchar(50), @dtEnd, 121) + ''' and publishername=''' + @publisher + 
               ''' order by endtimestamp, serialnumber';
set @outpath = '\\program files\appfolder\' + @publisher + '_January01.xml';

set @params  = 'bcp "' + @sql + '" queryout "' + @outpath + '" -T -c -r -t -x'

execute master..xp_cmdshell @params;


When I try to run this code, I get the following errors

<br />
SQLState = 08001, NativeError = 2 <br />
Error = [Microsoft][SQL Native Client]Named Pipes Provider: Could not open a connection to SQL Server [2]. <br />
<br />
SQLState = HYT00, NativeError = 0<br />
Error = [Microsoft][SQL Native Client]Login timeout expired <br />
<br />
SQLState = 08001, NativeError = 2<br />
Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the  default settings SQL Server does not allow remote connections.<br />
NULL


If I've logged into the sql server with Management Studio, and am running this from a query window, why do I get this error?

[EDIT]

I had to add "-S sqlservername" to the commandline


"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001


modified on Thursday, February 14, 2008 12:12 PM

GeneralOne to Many Atomic Update Pin
Brady Kelly14-Feb-08 1:32
Brady Kelly14-Feb-08 1:32 
QuestionUpdate a datatable to database Pin
Bluebamboo14-Feb-08 1:02
Bluebamboo14-Feb-08 1:02 
GeneralRe: Update a datatable to database Pin
Joe14-Feb-08 1:27
Joe14-Feb-08 1:27 
GeneralRe: Update a datatable to database Pin
Bluebamboo14-Feb-08 4:32
Bluebamboo14-Feb-08 4:32 
GeneralRe: Update a datatable to database Pin
Joe14-Feb-08 5:30
Joe14-Feb-08 5:30 
GeneralRe: Update a datatable to database Pin
Bluebamboo14-Feb-08 8:41
Bluebamboo14-Feb-08 8:41 
GeneralRe: Update a datatable to database Pin
Joe14-Feb-08 18:48
Joe14-Feb-08 18:48 
GeneralPassing Parameters to Strored Procedure Pin
dnsl13-Feb-08 23:36
dnsl13-Feb-08 23:36 
GeneralRe: Passing Parameters to Strored Procedure [modified] Pin
Vimalsoft(Pty) Ltd14-Feb-08 20:13
professionalVimalsoft(Pty) Ltd14-Feb-08 20:13 
GeneralRe: Passing Parameters to Strored Procedure Pin
Ashfield15-Feb-08 9:48
Ashfield15-Feb-08 9:48 
Generalerror in local works fine in server Pin
new2pgrmg13-Feb-08 23:21
new2pgrmg13-Feb-08 23:21 
GeneralRe: error in local works fine in server Pin
Joe14-Feb-08 0:03
Joe14-Feb-08 0:03 
GeneralRe: error in local works fine in server Pin
new2pgrmg14-Feb-08 1:13
new2pgrmg14-Feb-08 1:13 
GeneralSaving Image Pin
mwanyu13-Feb-08 21:11
mwanyu13-Feb-08 21:11 
GeneralRe: Saving Image Pin
Giorgi Dalakishvili13-Feb-08 22:43
mentorGiorgi Dalakishvili13-Feb-08 22:43 
Generalreplace '1/1/1900' to NULL in MS SQL Pin
John Sundar13-Feb-08 20:39
John Sundar13-Feb-08 20:39 
GeneralRe: replace '1/1/1900' to NULL in MS SQL Pin
Colin Angus Mackay13-Feb-08 21:11
Colin Angus Mackay13-Feb-08 21:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.