开发者

Calling sp_rename ( or other sp_ ) for SQL server 2008 from .Net Code

开发者 https://www.devze.com 2022-12-29 02:58 出处:网络
Is my the only option to wrap sp_ren开发者_JAVA技巧ame or similar into stored procedure and then

Is my the only option to wrap sp_ren开发者_JAVA技巧ame or similar into stored procedure and then

sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
sqlCommand.ExecuteNonQuery();


sp_rename is a stored procedure, so you should be able to call it like any other...


When you call it directly (i.e. without wrapping it in another stored procedure), what error are you getting?


As long as the user account with which you are connecting to the database has rights to call sp_rename, there is no reason you cannot call it just like any other stored procedure like so:

var connString = ...
using ( var conn = new SqlConnection( connString ) )
{
    using ( var cmd = new SqlCommand( "exec sp_rename 'Table_1', 'Table_2'", conn ) )
    {
        conn.Open();
        cmd.ExecuteNonQuery();
    }
}
0

精彩评论

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