Xp_cmdshell Statement Worked In SQL2000 Not In 2005
Dec 7, 2007
Code Block
Hi All,
I've got a stored procedure called from a trigger on another database. There are two xp_cmdshell statements in the procedure. One writes a couple variables, passed from the trigger, into a text file. The second fires off an executable that uses the text file via a batch file.
Here's the code that worked on the old 32bit SQL2000 box
The new box is 64bit SQL2005. When invoked the stored procedure executes without an error. The textfile is written sucessfully. But, the executable called from the second xp_shell statement does not produce the expected result. Because there is no error I'm having trouble determining where the failure lies.
To troubleshoot the problem I've tried:
Running the batch file from the command prompt in the system32 directory... Success
Using sp_xp_cmdshell_proxy_account to be sure of the credentials of the running xp_cmdshell... Failure
My questions:
Does 64 Bit SQL2005 have a different set of parameters when invoking an executable from xp_cmdshell? ie Do I need to rewrite the batch file?
Is there another way call an executable, SQLCMD maybe?
Hi there, I have a query with a rather large (46 table) 1:1 join. Technically, I'm creating a view then trying to select from that view. I seem to be able to create the view ok but cannot resolve a select from it. The error message is:
Msg 8180, Level 16, State 1, Line 1 Statement(s) could not be prepared. Msg 191, Level 15, State 1, Line 1 Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries. Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near 'WHERE'.
This worked in 2000 without a problem
Here is the join:
FROM [HUSKY].USEP0712E.dbo.AGAF_us T1 INNER JOIN [HUSKY].USEP0712E.dbo.AGAM_us T2 ON T1.CODE = T2.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGASN_us T3 ON T1.CODE = T3.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGBF_us T4 ON T1.CODE = T4.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGBLK_us T5 ON T1.CODE = T5.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGBM_us T6 ON T1.CODE = T6.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGHF_us T7 ON T1.CODE = T7.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGHM_us T8 ON T1.CODE = T8.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGHSP_us T9 ON T1.CODE = T9.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGIF_us T10 ON T1.CODE = T10.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGIM_us T11 ON T1.CODE = T11.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGIND_us T12 ON T1.CODE = T12.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGNH_us T13 ON T1.CODE = T13.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGNHF_us T14 ON T1.CODE = T14.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGNHM_us T15 ON T1.CODE = T15.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGOF_us T16 ON T1.CODE = T16.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGOM_us T17 ON T1.CODE = T17.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGOTH_us T18 ON T1.CODE = T18.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGWF_us T19 ON T1.CODE = T19.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGWHT_us T20 ON T1.CODE = T20.CODE INNER JOIN [HUSKY].USEP0712E.dbo.AGWM_us T21 ON T1.CODE = T21.CODE INNER JOIN [HUSKY].USEP0712E.dbo.WH_AOH_us T22 ON T1.CODE = T22.CODE INNER JOIN [HUSKY].USEP0712E.dbo.WNH_AONH_us T23 ON T1.CODE = T23.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGAF_us T24 ON T1.CODE = T24.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGAM_us T25 ON T1.CODE = T25.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGASN_us T26 ON T1.CODE = T26.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGBF_us T27 ON T1.CODE = T27.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGBLK_us T28 ON T1.CODE = T28.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGBM_us T29 ON T1.CODE = T29.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGHF_us T30 ON T1.CODE = T30.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGHM_us T31 ON T1.CODE = T31.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGHSP_us T32 ON T1.CODE = T32.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGIF_us T33 ON T1.CODE = T33.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGIM_us T34 ON T1.CODE = T34.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGIND_us T35 ON T1.CODE = T35.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGNH_us T36 ON T1.CODE = T36.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGNHF_us T37 ON T1.CODE = T37.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGNHM_us T38 ON T1.CODE = T38.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGOF_us T39 ON T1.CODE = T39.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGOM_us T40 ON T1.CODE = T40.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGOTH_us T41 ON T1.CODE = T41.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGWF_us T42 ON T1.CODE = T42.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGWHT_us T43 ON T1.CODE = T43.CODE INNER JOIN [HUSKY].USEP0712P.dbo.AGWM_us T44 ON T1.CODE = T44.CODE INNER JOIN [HUSKY].USEP0712P.dbo.WH_AOH_us T45 ON T1.CODE = T45.CODE INNER JOIN [HUSKY].USEP0712P.dbo.WNH_AONH_us T46 ON T1.CODE = T46.CODE
I have SQL 2000 Standard edition installed on a Windows server 2003 on a virutal box. SQL was upgraded to 2005 but during the install wizard, it did not prompt me for the Instance Name to upgrade. When done, I see the SQL Management Studio and when I connect, my databases are listed in the studio but the version number says 8.0.760 across the top of management studion which is SQL 2000 sp3.
Enterprise Manager is still available. It appears SQL 2005 was installed side by side with SQL 2000. Does that sound correct?
I downloaded SQL 2005 standard edition from my open license agreement. Don't know if that makes a difference.
I also tried upgrading SQL 2005 via the command prompt and it still shows verison number 8.0.760.
I am developing an app in VB.Net 2005, and I installed SQL Server 2005 locally on my machine. My app access multiple databases on SQL and has worked like a charm in the past. Today, when I go to access my app, I receive an error when trying to connect to the SQL database.
"An error has occured 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 connection"
As I said before, this is a local install and worked fine until today. I checked the services running and Here is what I have:
SQL Server Integration Services - Running SQL Server FullText Search - Stopped SQL Server(SQLEXPRESS) - Running SQL SERVER (MSSQLSERVER) - Stopped <---------- I tried restarting this and it times out SQL Server Analysis Services (MSSQLSERVER) - Stopped SQL Server Reporting Services (MSSQLSERVER) - Stopped SQL Server Browser - Stopped SQL Server Agent (MSSQLSERVER) - Stopped
I am unable to start any of these services... they all time out. Any help would be greatly appreciated!
Hi, I want to copy xls file from remote server to my server. i want to use xp_cmdshell to perform this operation. can anybody help me out how to pass parameter to xp_cmdshell.
I was trying to grant access for an application user for executing xp_cmdshell, but I got some error message saying that either doesn't the user exist, or I don't have the permissions to grant this. Does the user need to be a user in Master ? Or, don't I when logged in as "sa" have the sufficient permissions to grant execute on a SP in master?
I solved it by checking "Control server" under "Properties" > "Securables" for the login, but I don't actually want this login to have full control.
(And yes, I've read that allowing xp_cmdshell usage isn't recommended at all.)
Msg 15121, Level 16, State 200, Procedure xp_cmdshell, Line 1 An error occurred during the execution of xp_cmdshell. A call to 'LogonUserW' failed with error code: '1326'.
... and yes, the username and password should be valid ;-)
When I exec (makes no sense, I now...)
EXEC xp_cmdshell 'echo 123'
The following error occurs:
Msg 15121, Level 16, State 200, Procedure xp_cmdshell, Line 1 An error occurred during the execution of xp_cmdshell. A call to 'LogonUserW' failed with error code: '1326'.
I'm just moving over one of our databases from SQL2000 to 2005. Everything is working fine, and all web sites are working, however I just can't seem to get xp_cmdshell to function on the 2005 server.
I have enabled xp_cmdshell, and when I run a stored procedure, which writes the contents of one column to a text file, it says "invalid object name". This table is definitely there, and is actually updated earlier on in the same SP, so permissions for that are fine.
This is the line causing the problem (if I take it out, the rest of the SP works no problems):
--write the text file EXEC master.sys.xp_cmdshell 'bcp "SELECT newslettertext FROM mydatabase.dbo.newsletters" queryout D:ewslettertext extbody.txt -U -P -c'
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'mydatabase.dbo.newsletters'.
SQLState = 37000, NativeError = 8180 Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. NULL
Could it be to do with permissions on the master.sys.xp_cmdshell? If so, wouldn't it give me a "permission denied" error?
SQL Server 2005: Microsoft SQL Server Enterprise Edition (64-bit) Microsoft Windows NT 5.2 (3790)
SQL Version 9.00.3175.00
I have 2 identical servers... one for DEV and one for TEST. On the DEV server, I can use xp_cmsdhell to execute "administrative commands" such as NET SHARE and AT. On the identically configured TEST server, I can not. Those command return the "System error 5 has occurred. Access is denied" error. I CAN run other commands via xp_cmdshell (DIR, NET USE, etc.). This is true regardless of the account I connect as.
The SQL Server service accounts in both instances are domain accounts belonging to the local admin group.
I "know" that I ran across this when setting up the DEV server and am "fairly sure" I found a reference to a known problem with 2005's xp_cmdshell and administrative commands. But for the life of me I can not now find any such reference, nor can I find any differences between the DEV and TEST servers in the area of users, groups, policies, or anything else security-related. (99.9% of the internet searches I do end up being about either enabling xp_cmdshell -- done -- or setting up an xp_cmdshell proxy account -- not needed).
I am using the xp_cmdshell to run a batch file that is trying to open the Adobe Acrobat Reader.
When I run the batch file in the command prompt, it opens perfectly.
When I run it in SQL with xp_cmdshell, it returns the contents fine, and I notice it tries to open Acrobat, but it is under the username "system". And I cannot get it to load in a visible area, and for some reason it doesnt seem to load properly under system.
Hi, I have a least privileged SQL Login €œClient€? and have granted execute rights on XP_Cmdshell SP at master db. When I execute master.. XP_Cmdshell €˜dir€™ I€™m getting the below error.
Msg 15153, Level 16, State 1, Procedure xp_cmdshell, Line 1 The xp_cmdshell proxy account information cannot be retrieved or is invalid. Verify that the '##xp_cmdshell_proxy_account##' credential exists and contains valid information.
Please note it is SQL Login account and not windows account. I have checked everywhere for similar problem and no luck.
We have a financial accounting system that has been certified for SQL 2005. Before I upgrade, I'm wondering if I should expect better/faster performance from SQL 2005 vs. SQL 2000?
Anything I should lookout for when upgrading to SQL 2005?
I've passed my ASP application database from SQL Server2000 to SQL Server 2005 and have some problems with the new functions in SQL Server2005, which do not acsept the Date & Time format as SQL 2000..in insert query.
Of course, I'd like to delete the AdStatPageHeure_OLD table but I get a cryptic error message when doing that, and I can't remove the indexes that, according to some other posts I browsed, could explain the behavior: ---
La page (1:1111186), slot 1 pour le noeud text, ntext ou image n'existe pas. Page (1:1111186), slot 1 for text, ntext, or image node does not exist. (Microsoft SQL Server, Erreur : 7105)
Pour obtenir de l'aide, cliquez sur : http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=7105&LinkId=20476 ---
Is there any easy option you can see to operate the transfer, since the backups I have from the DB already contain the data corruption?
Thanks a lot for any hint you could provide, -- Julien
My company wants to combine our SQL2000 and SQL2005 severs onto one server. If I install SQL2000 and 2005 on one server and migrate the data bases will I have any performance issues? Is there any issues or conflicts known by putting them both on the same server?
Could you please help me on this issue.It is URgent .I am new to SSIS.
I am using DTS package in SSIS. I Have an SQLTask and DTS Package. I want to fail the SSIS PAckage when DTS 2000 Package Fails. I want to know How to populate the failure of DTS PAcage to SSIS PAcage.When i execute the SSIS Package the DTSPAckage task Failed Internally but it styays yellow for ever.it is not showing red Color in SSIS Package.Any help is greatyly appreciated.
Ok, I know that there is a very smart programmer out there that can resovle my issue.
I am trying to calculate time worked by 15 minute intervals.
Example: Emp 1 started work at 13:00:00 and worked 183 minutes Emp 2 started work at 17:15:00 and worked 150 minutes Emp 3 started work at 08:30:00 and worked 17 minutes
In €˜X€™ server, I have a linked server named €˜CustSrv€™ which is connecting to €˜Z€™ server In the €˜Z€™ server I have a Database named €˜SalesDB€™
I have a view name vw_CusgtomerData in my €˜X€™ server which is selecting data from SALESDB..Customer_Tbl from the €˜Z€™ server through that linked server (€˜CustSrv€™)
The View is simple selecting data from Customer_Tbl from SalesDB
SELECT * FROM CustSrv.SalesDB.dbo.CUSTOMER_Tbl
[Note here using * for all columns?? Is it ok for performance aspects]
Now I have some Application which are using that view through some stored procedure.Few of them passing some parameters like Cust_Id etc
Now my query is that.. Am I fulfilling all performance issues?
Or
What is the suggestive way to fetch data from that remote (Linked Server) server to get good performance benefit?
In my opinion we can fetch data 4 different way from that linked server€¦
A.SELECT * FROM CustSrv.SalesDB.dbo.CUSTOMER_Tbl
B.exec GetCustomerData 65 [Sp_GetCustomerData is a Storedprocedure which is passing a parameter 65 that is Customer_ID and the procedure is selecting data from the view vw_CusgtomerData]
C.SELECT cu_customer_id, cu_customer_name FROM vw_CusgtomerData ORDER BY cu_customer_name Or SELECT * FROM vw_CusgtomerData where Customer_ID=65
D.select * FROM OPENQUERY (CustSrv,'SELECT Customer_ID,cu_customer_name FROM SalesDB.dbo. CUSTOMER_Tbl ORDER BY cu_customer_name ')
Am I bypass the concept of view and fetch data directly in the stored procedure through the linked server ??
I've come up against a wall with regards to adding login via a windows group. My end goal is to be able to manage sysadmin access to many servers via a domain group instead of via individual logins at each server.
I've got a mix of 2000 and 2005 servers, with a related issue for each. Searching far and wide has come up empty so far.
In each case below, the a login for the group was created via EM/SSMS, and set with the sysadmin role.
1. Domain Local Group
I added a domain local group "domainsql accounts" with myself among others as members, including the domain account for the sql and agent services.
Adding this group to SQL2005 worked fine, and authenticates my login as a member of this group. Oddly, xp_logininfo [domainsql accounts] , 'members' returns error code 0x8ac. It does log me in, and it does correctly grant me sysadmin.
Adding this group to SQL2000 from EM, the group does not appear in the list for the domain. Typing it manually does recognize it as a group, but it does not allow login.
Next, I added a global group "domainsql dba", with myself among others as members. This group IS viewable in SQL2000 EM to add as a login. Unfortunately, I still cannot login via windows auth. Even stranger, xp_logininfo [domainsql dba] , 'members' correctly returns the members of this group. I know SQL can authenticate that group, and I am part of that group, yet it won't authenticate my login?
SQL2005 fails to allow login but will also return member info via xp_logininfo.
The closest thing I found was a MS kb entry that suggested creating a local group, adding the domain group as a member of the local group, and adding a login for the local group. It didn't work.
I created a DTS Package. It worked fine if I execute the DTS from DTS designer. It failed after I right clicked to Schedule Package, and than right clicked on the job to Start Job from Management - SQL Server Agnet - Jobs. When I clicked View Job History, the error was "The job failed. The last step to run was step 1 (DTSPackageName).
Why did it fail from scheduled DTS? Thanks. DanYeung
I have an application which stores records on a local SQL Express and I need to move the records to a SQL 2000 database. I have the SQL 2000 server linked in the Express Management Console (under Linked Servers). I'm trying to use a stored procedure to accomplish this, but get an error "Invalid object name 'ngtxa4-rsmsz-01.newpurchase.tblRequest'." Express uses a table named tblTRequest in the TempPurchase database, while 2000 uses a table named tblRequest in a NewPurchase database. Here is the stored procedure I'm using: USE [tempPurchase] GO /****** Object: StoredProcedure [dbo].[InsertRequestToMain] Script Date: 07/09/2007 08:54:56 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[InsertRequestToMain] AS BEGIN INSERT INTO [ngtxa4-rsmsz-01].newpurchase.tblRequest (fldRequestDate, fldRequiredBy, fldUserID, fldWorkAreaID, fldVendorID, fldClassID, fldEstimate, fldMemo, fldStatusID, fldStatusDate, fldSystemID, fldtmpRequestID, fldUpdateCode) SELECT fldRequestDate, fldRequiredBy, fldUserID, fldWorkAreaID, fldVendorID, fldClassID, fldEstimate, fldMemo, fldStatusID, fldStatusDate, fldSystemID, tmpRequestID, UpdateCode FROM tblTRequest WHERE (fldHold = 0) END
Any assistance with this would greatly be helpful. Thank you.
I create a package that has a foreach loop container, inside the FE container the is a dataflow, script task and a file system task, on the outside of the FE loop I have a SQL execute SQL task. I had it working then it just stopped. Been looking to see why but can't see why, is there something I missed. I changed the onError script task event handler, to propagate = false, because the last file in the source directory is being written to until 11:59 pm and is locked, and I get error file is being used by another process. I am at a loss as to why it would just stop working.
Hi, I am trying to enable remote access on a SQL Server 2005 standard edition instance. I have enabled it in the properties using the Management studio and have enabled it under Sql Server Surface Area Configuration under "Database engine".
But it didn't work. I know for a fact that my connection string is correct (I tested it on the actual machine)
So I checked everything again and I noticed in the Sql Server Surface Area under "Analysis Services" there is another "remote connection" checkbox to be enabled, however it won't let me enable it there because it says the "Sql Browser" is not started. I checked and the Sql Browser is started.
I'm thinking maybe the problem there is that I have an instance of SQL 2000 running and perhaps it is the sql browser for that (I can remotely connect ot my SQL 2000 instance).
I checked under Computer management -> services and their is no SQL Browser for the instance of SQL 2005. Not even a thing to enable. Just the Default instance SQL Browser, which is for my SQL 2000 instance. Am I missing something here?
Also there is no SQL Browser to enable in the management or Surface Area Configuration programs.
I have also tried to connect using the default port number (1433) and the IP (to bypass the need for the SQL Browser). It apparently finds my Server 2000 instance because it doesn't accept my user name and password and connot find the specific database (note: I verified the username and pswd are correct by testing the values on the SQL machine). How do I find what port number a specific instance of SQL Server is running on?