开发者

Check if I can execute some sql-command

开发者 https://www.devze.com 2022-12-19 09:44 出处:网络
I\'m using ADO .NET and MS SQL Server 2008. I have a connection object to a server and a command: SqlConnection conn = /* my connection*/;

I'm using ADO .NET and MS SQL Server 2008.

I have a connection object to a server and a command:

SqlConnection conn = /* my connection*/;
string cmd = "some_sql_command";

I want to check if SQL Server can execute cmd. I don't want to execute cmd, but I want to know If SQL Server can execute it.

cmd can be any single开发者_Python百科 SQL statement, it's not a procedure, transaction or multiple commands etc..


Well, you can always start a transaction, execute the command and then roll back the transaction so that no changes are made to the database.

Another option is to use ServerConnection.ExecuteNonQuery method, which, when passed ParseOnly flag, only parses the command and does not do anything else.

0

精彩评论

暂无评论...
验证码 换一张
取 消