private void AttachDataBase()
{
string Str_mdf;
string Str_ldf; Str_mdf = "E:\\DataBase\\Test_Data.MDF";
Str_ldf = "E:\\DataBase\\Test_log.LDF"; SqlCommand thisCommand = new SqlCommand("sp_attach_db",SQLConn); thisCommand.CommandType = System.Data.CommandType.StoredProcedure; thisCommand.Parameters.Add(new SqlParameter("@dbname", SqlDbType.NChar, 50, "Test"));
thisCommand.Parameters.Add(new SqlParameter("@filename1", SqlDbType.NChar, 200, Str_mdf));
thisCommand.Parameters.Add(new SqlParameter("@filename2", SqlDbType.NChar, 200, Str_ldf)); thisCommand.ExecuteNonQuery();
}
为何出错?
{
string Str_mdf;
string Str_ldf; Str_mdf = "E:\\DataBase\\Test_Data.MDF";
Str_ldf = "E:\\DataBase\\Test_log.LDF"; SqlCommand thisCommand = new SqlCommand("sp_attach_db",SQLConn); thisCommand.CommandType = System.Data.CommandType.StoredProcedure; thisCommand.Parameters.Add(new SqlParameter("@dbname", SqlDbType.NChar, 50, "Test"));
thisCommand.Parameters.Add(new SqlParameter("@filename1", SqlDbType.NChar, 200, Str_mdf));
thisCommand.Parameters.Add(new SqlParameter("@filename2", SqlDbType.NChar, 200, Str_ldf)); thisCommand.ExecuteNonQuery();
}
为何出错?
解决方案 »
- csdn 2012年度.NET最有价值问题评选第一名的问题
- winform 复制
- 100分求助达人提供AS2 EDI的资料,IPWork组件的使用.帮顶也有分.
- 求在DockPanel的子窗体打开另一子窗体使其停靠在主窗体的方法
- 获得公网ip
- 关于继承的权限问题?
- 无法创建 Excel.Application xApp = new Excel.Application();
- 树型结构删除一个结点以后不自动刷新,该怎么解决?
- 新手求助!关于C#写Modbus TCP的问题 谢谢!
- 小女子在此跪求C#报错“尝试读取或写入受保护的内存,这通常是指内存已经损坏”
- 那个高手可以帮我优化一下这个循环?
- 问一问 OA
thisCommand.Connection = SQLConn;
thisCommand.CommandType = CommandType.StoredProcedure;
thisCommand.CommandText = "Pro_Insert"; //存储过程名thisCommand.Parameters.Add("@dbname",SqlDbType.NChar,50);
没有打开!
thisCommand.CommandType = System.Data.CommandType.StoredProcedure;
它怎么知道去哪里找sp_accach_db存储过程?
改成:SQLConn.Open();thisCommand.ExecuteNonQuery();
SQLConn.Close();数据库连接要打开。