111,130
社区成员
发帖
与我相关
我的任务
分享SqlCommand thisCommand = new SqlCommand(SqlCommandText ,SQLConn);
class Program
{
static void Main(string[] args)
{
string mdf = @"C:\test.mdf";
string ldf = @"C:\test_log.ldf";
string cmd = string.Format("sp_attach_db");
SqlConnection connection = new SqlConnection("Server=(local); Database=master; Integrated Security=SSPI");
connection.Open();
SqlCommand command = new SqlCommand();
command.Parameters.Add(new SqlParameter("dbname", "Liu"));
command.Parameters.Add(new SqlParameter("filename1", mdf));
command.Parameters.Add(new SqlParameter("filename2", ldf));
command.Connection = connection;
command.CommandText = cmd;
command.CommandType = CommandType.StoredProcedure;
command.ExecuteNonQuery();
}
}