Is my the only option to wrap sp_rename or similar into stored procedure and then
sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
sqlCommand.ExecuteNonQuery();
Is my the only option to wrap sp_rename or similar into stored procedure and then
sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
sqlCommand.ExecuteNonQuery();
When you call it directly (i.e. without wrapping it in another stored procedure), what error are you getting?
sp_rename
is a stored procedure, so you should be able to call it like any other...
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();
}
}