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();
}
}
精彩评论