从 UNIX 上的 Web 应用程序调用存储过程会在 xp_cmdshell 上抛出错误
嘿大家,我正在为这件事抓狂。
我已经检查了数据库服务器 (SQL Server 2000) 和文件系统上的所有权限,以确保我尝试执行的操作是可行的。 情况如下:
我有一个 Java EE Web 应用程序在公司 Intranet 上的 Tomcat 服务器上运行。 长话短说,该应用程序处理数字,创建一个以管道分隔的记录文件,以便批量插入到我们的数据库中,并将该文件保存在 UNIX 服务器上。
然后调用一个存储过程,它利用 xp_cmdshell 将文件从 UNIX FTP 到我们的 Windows SQL Server 框,以便批量插入该文件。 当我从 Management Studio 调用此存储过程(以运行 Web 应用程序的 tomcat 用户身份登录)时,没有出现任何错误,并且 FTP 进行传输并加载文件。
这是让我恼火的部分。
当 Java EE 应用程序调用此存储过程时,它实际上将文件通过 FTP 传输到 SQL Server 框,但即使成功,我最终也会遇到 SQLServerException。 没有押韵或理由。 但是......即使抛出异常,我的文件最终会在服务器上一切顺利且舒适。
SQL Server 在从 UNIX 服务器运行 xp_cmdshell 时是否存在问题(这对我来说听起来很可笑,因为该程序所做的只是调用存储过程,周二晚上 11:55 我仍在办公室,所以我想没有什么太可笑的...)
任何见解都会很棒...
编辑:
此外,我一直在使用 SQL Profiler 查看 SQL Server 的流量...并且我可以看到我用来调用的实际语句存储过程。 当我将其复制到 SQL Server Management Studio 并使用我的 tomcat 用户凭据执行它时,它执行完美......
Hey all, I'm pulling my hair out on this one.
I've checked all my permissions, on both the database server (SQL Server 2000) and the file system to ensure that what I am trying to do should be possible. Here's the situation:
I have a Java EE web application running on a Tomcat server on my company's intranet. Long story short, this application crunches numbers, creates a pipe-delimited file of records to be BULK INSERTed into our database, and saves the file on the UNIX server.
Then a stored procedure is called which utilizes xp_cmdshell to FTP the file from UNIX to our Windows SQL Server box in order to BULK INSERT the file. When I call this stored procedure (logged in as the tomcat user that we run our web app from) from Management Studio, there is not a single error, and the FTP transfers, and the file is loaded.
This is the part that is aggravating me.
When the Java EE app calls this stored procedure, it actually FTPs the file to the SQL Server box, but I end up with a SQLServerException even upon success. No rhyme or reason. BUT...even though the exception is thrown, my file ends up on the server all nice and cosy.
Does SQL Server have an issue with running xp_cmdshell from a UNIX server (as ludicrous as this sounds to me, since all the program is doing is calling a stored procedure, I am still at the office at 11:55PM on a Tuesday night, so I guess nothing is too ludicrous...)
Any insight would be great...
EDIT:
Also, I have been viewing the traffic to SQL Server using SQL Profiler...and I can see the actual statement I am using to call the stored procedure. When I copy that into SQL Server Management Studio and execute it using my tomcat user credentials it executes flawlessly...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哇。 这就是为什么晚上 11 点写代码不好的原因。
xp_cmdshell 在每次执行时返回一个结果集。 它基本上为您提供命令行的输出,就像您在命令提示符处看到的那样。 这里的关键是结果集。
我调用存储过程的 JDBC 方法是 issuesUpdate(),它在 xp_cmdshell 返回的结果集上引发异常。 当我更改为 issuesQuery() 时,我没有收到异常,并且其余代码执行完毕。
我认为我需要做一些工作来清理这个问题,但我对这个解决方案感到满意。
Wow. This is why it is not good to code things at 11PM.
xp_cmdshell returns a result set on every execution. It basically gives you the output from the command line as you would see it at a command prompt. The key here is result set.
The JDBC method I was calling to invoke the stored procedure was issueUpdate(), which was throwing an exception on the returned result set of xp_cmdshell. When I changed to issueQuery(), I did not receive the exception and the rest of my code executed to completion.
I think I have some work to do to clean this up, but I am satisfied with this solution.