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();
        }
为何出错?

解决方案 »

  1.   


    thisCommand.Connection = SQLConn;
    thisCommand.CommandType = CommandType.StoredProcedure;
    thisCommand.CommandText = "Pro_Insert"; //存储过程名thisCommand.Parameters.Add("@dbname",SqlDbType.NChar,50);
      

  2.   

    thisCommand.CommandText = "Pro_Insert"; //这里要指定存储过程名 不然怎么找?
      

  3.   

    SqlCommand thisCommand = new SqlCommand("sp_attach_db",SQLConn); 缺少DBOwnerSqlCommand thisCommand = new SqlCommand("dbo.sp_attach_db",SQLConn); lz把错误贴来看看
      

  4.   

    SQLConn.Open() 
    没有打开!
      

  5.   

    SqlCommand thisCommand = new SqlCommand("sp_attach_db",SQLConn); 
    thisCommand.CommandType = System.Data.CommandType.StoredProcedure; 
    它怎么知道去哪里找sp_accach_db存储过程?
      

  6.   

    thisCommand.ExecuteNonQuery(); ----------------------------------------
    改成:SQLConn.Open();thisCommand.ExecuteNonQuery(); 
    SQLConn.Close();数据库连接要打开。
      

  7.   

    连结打开了,都正学,调用"Select ...."都正常.就是执行存储过程,不能正常运行.没有错误提示,程序执行到这句,不往下执行,而是跳出了.
      

  8.   

    是不是路径不是服务器上的,SQL只认本地硬盘的,所以你给出的路径一定要是服务器上的路径才行。
      

  9.   

    存储过程在SQL里是否能正常运行?检查存储过程参数是否与Add参数相同?