-1

デスクトップに MS Sql Server 2012 をインストールし、ac# プログラムを書き込もうとしています。

DBファイルをSQL Server 2012に添付すると、プログラムの実行中にエラーメッセージがスローされます

以下に記載されているように、解決するために私を助けてもらえますか

MS SQL Server 2012 によってスローされる以下のエラー メッセージ、

DB ファイル (mdf および ldf)

以下のコードを使用:

方法 :

AttachDb("sqlDb","[C:\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\sqlDb.mdf] [C:Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\sqlDb_log.ldf]");

エラーメッセージ :

    80131501 Error: An exception occurred while executing a Transact-SQL statement or batch.
    From: Microsoft.SqlServer.ConnectionInfo
     at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
        at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType)
        at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries)
        at Microsoft.SqlServer.Management.Smo.Server.AttachDatabaseWorker(String name, StringCollection files, String owner, AttachOptions attachOptions)
        at Microsoft.SqlServer.Management.Smo.Server.AttachDatabase(String name, StringCollection files)
    80131500 Error: Attach database failed for Server 'sqlDbServer'. 
     From: Microsoft.SqlServer.Smo
        at Microsoft.SqlServer.Management.Smo.Server.AttachDatabase(String name, StringCollection files)
        at TestSMO.AttachDb(String dbname, String filelist) 

コード:

     static string instance = "";
     static string username = "";
     static string password = "";
     static string connection_timeout = "600";
     static string statement_timeout  = "3600";

    //create server connection object 
    static Server Connect()
    {
    ServerConnection conn = new ServerConnection();
    instance="sqlDbServer";
    if (instance.Length > 0)
        conn.ServerInstance = instance;

    if (username.Length > 0) {
        conn.LoginSecure = false;
        conn.Login = username;
        conn.Password = password;
    }

    conn.ConnectTimeout = Convert.ToInt32(connection_timeout);
        conn.StatementTimeout = Convert.ToInt32(statement_timeout);
        return new Server(conn);
    }



    //performing attache DB 
     static void AttachDb(string dbname, string filelist)
        {
            string[] files = filelist.Split(new char[] {'['}, StringSplitOptions.RemoveEmptyEntries);
            StringCollection dbfiles = new StringCollection();
            foreach (string s in files) {
                string s1 = s.TrimEnd(null);
                s1 = s1.TrimEnd(']');
                if (s1.Length > 0) dbfiles.Add(s1);
            }
            Server svr = Connect();
            string name = DecodeString(dbname);
            svr.AttachDatabase(name, dbfiles);
        }
4

1 に答える 1

-1

SQL Server DB インスタンスのNT AUTHORITY\SYSTEMログインにすべてのサーバー ロールを提供することで問題が解決しました。

于 2012-10-10T13:20:45.103 に答える