Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Configure 'Allow Updates' Expand / Collapse
Author
Message
Posted Wednesday, May 15, 2013 7:57 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, February 20, 2014 9:07 AM
Points: 52, Visits: 131
hi there, hope in your help.

I tried this code in sql server, but I've this error.
Can you help me?
I would really appreciate any help.
sp_configure 'Allow Updates',
0;

RECONFIGURE WITH override;

EXEC master.dbo.sp_configure 'show advanced options',
1 RECONFIGURE EXEC master.dbo.sp_configure 'xp_cmdshell',
1 RECONFIGURE EXEC xp_cmdshell 'bcp "SELECT * FROM [dbo].[tbl];" queryout "\\XX.XX.XX.XX\output.txt" -T -c -t;'


SQLState = 08001, NativeError = 2
Error = [Microsoft][SQL Server Native Client 10.0]Named Pipes Provider: Could not open a connection to SQL Server [2].
SQLState = 08001, NativeError = 2
Error = [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while
establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct
and if SQL Server is config
ured to allow remote connections. For more information see SQL Server Books Online.
SQLState = S1T00, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Login timeout expired

Post #1453110
Posted Wednesday, May 15, 2013 2:42 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 5:14 PM
Points: 7,125, Visits: 12,719
cms9651 (5/15/2013)
hi there, hope in your help.

I tried this code in sql server, but I've this error.
Can you help me?
I would really appreciate any help.
sp_configure 'Allow Updates',
0;

RECONFIGURE WITH override;

EXEC master.dbo.sp_configure 'show advanced options',
1 RECONFIGURE EXEC master.dbo.sp_configure 'xp_cmdshell',
1 RECONFIGURE EXEC xp_cmdshell 'bcp "SELECT * FROM [dbo].[tbl];" queryout "\\XX.XX.XX.XX\output.txt" -T -c -t;'


SQLState = 08001, NativeError = 2
Error = [Microsoft][SQL Server Native Client 10.0]Named Pipes Provider: Could not open a connection to SQL Server [2].
SQLState = 08001, NativeError = 2
Error = [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while
establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct
and if SQL Server is config
ured to allow remote connections. For more information see SQL Server Books Online.
SQLState = S1T00, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Login timeout expired



A few things:

1. 'Allow Updates' has not done anything since SQL 2005 was released so you can drop that from your script. Reference
2. Do not use RECONFIGURE WITH OVERRIDE; unless you have a good reason. I know SSMS spits it out when you script a change done through the GUI, but I would recommend against ever executing it in a script.
3. Are you sure you want to use xp_cmdshell? Only use it if you have no other options, and I am confident that I can help you find a better option. At a higher level than just "I need to get data from a table into a file", what exactly are you designing?


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1453275
Posted Thursday, May 16, 2013 1:13 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, February 20, 2014 9:07 AM
Points: 52, Visits: 131
thank you for help.
I need to get data from a table into a file txt.
Post #1453345
Posted Thursday, May 16, 2013 6:06 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, October 31, 2013 3:44 AM
Points: 314, Visits: 4,128
Is this going to be an ongoing process or is it just a one-off?
Post #1453460
Posted Thursday, May 16, 2013 6:11 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, February 20, 2014 9:07 AM
Points: 52, Visits: 131
This is an ongoing process, planned in the server
Post #1453464
Posted Thursday, May 16, 2013 7:12 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 5:14 PM
Points: 7,125, Visits: 12,719
Are you on an Edition of SQL Server that has SQL Agent? In other words not SQL Express Edition?

If so, I would recommend you setup a SQL Agent Job to run bcp for you. When you setup the job, the Job Step Type will be "Operating System (CmdExec)" and in the command you will put your call to bcp. Then you can schedule the job to run as needed.


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1453509
Posted Thursday, May 16, 2013 7:25 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, February 20, 2014 9:07 AM
Points: 52, Visits: 131
opc.three (5/16/2013)
Are you on an Edition of SQL Server that has SQL Agent? In other words not SQL Express Edition?


Not Sir, the db is to remote server and I use the navicat SQL Server for connected to db
Post #1453518
Posted Thursday, May 16, 2013 7:25 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, October 8, 2014 5:24 AM
Points: 323, Visits: 532
OPC has got it. An SQL Server Agent job with BCP is definately the answer.

If however you have an Express version, I would recommend creating an OS-level Batch Job that calls BCP and then running the batch using Windows Scheduler.
Post #1453519
Posted Thursday, May 16, 2013 8:56 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, February 20, 2014 9:07 AM
Points: 52, Visits: 131
I tried this but the table is not exporting in txt file:
[SQL] DECLARE
@SQL VARCHAR (8000) SELECT
@SQL = 'bcp mytable out \\XX.XX.XX.XX\output.txt -T -c -t'
Affected rows: 0
Time: 0.041ms

Affected rows: 0


Post #1453598
Posted Thursday, May 16, 2013 9:15 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 7:24 AM
Points: 31,161, Visits: 15,608
It's possible you are getting an error on the pathing that you don't see. The command will require that the account running SQL Server (service account) has rights to the \\xx.xx.xx.xx\xx share.

What you might try doing is double checking rights or changing to a local path for testing. Then if the bcp works, you can add the specific rights to the service account.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1453617
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse