How to restore SQL Server database through C# code

前端 未结 6 1686
我寻月下人不归
我寻月下人不归 2020-12-08 21:12

I try to restore the database like this:

SQL = @\"RESTORE DATABASE MyDataBase TO DISK=\'d:\\MyDATA.BAK\'\";
                Cmd = new SqlCommand(SQL, Conn);
         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 21:53

    You must connect to the database server via a different database.

    So your connection string should take you to say "Master" or another database on the server, then you can complete the task at hand.

提交回复
热议问题