Guest User

Untitled

a guest
Jan 19th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. AttachDb("sqlDb","[C:Microsoft SQL ServerMSSQL11.MSSQLSERVERMSSQLDATAsqlDb.mdf] [C:Microsoft SQL ServerMSSQL11.MSSQLSERVERMSSQLDATAsqlDb_log.ldf]");
  2.  
  3. 80131501 Error: An exception occurred while executing a Transact-SQL statement or batch.
  4. From: Microsoft.SqlServer.ConnectionInfo
  5. at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
  6. at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType)
  7. at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries)
  8. at Microsoft.SqlServer.Management.Smo.Server.AttachDatabaseWorker(String name, StringCollection files, String owner, AttachOptions attachOptions)
  9. at Microsoft.SqlServer.Management.Smo.Server.AttachDatabase(String name, StringCollection files)
  10. 80131500 Error: Attach database failed for Server 'sqlDbServer'.
  11. From: Microsoft.SqlServer.Smo
  12. at Microsoft.SqlServer.Management.Smo.Server.AttachDatabase(String name, StringCollection files)
  13. at TestSMO.AttachDb(String dbname, String filelist)
  14.  
  15. static string instance = "";
  16. static string username = "";
  17. static string password = "";
  18. static string connection_timeout = "600";
  19. static string statement_timeout = "3600";
  20.  
  21. //create server connection object
  22. static Server Connect()
  23. {
  24. ServerConnection conn = new ServerConnection();
  25. instance="sqlDbServer";
  26. if (instance.Length > 0)
  27. conn.ServerInstance = instance;
  28.  
  29. if (username.Length > 0) {
  30. conn.LoginSecure = false;
  31. conn.Login = username;
  32. conn.Password = password;
  33. }
  34.  
  35. conn.ConnectTimeout = Convert.ToInt32(connection_timeout);
  36. conn.StatementTimeout = Convert.ToInt32(statement_timeout);
  37. return new Server(conn);
  38. }
  39.  
  40.  
  41.  
  42. //performing attache DB
  43. static void AttachDb(string dbname, string filelist)
  44. {
  45. string[] files = filelist.Split(new char[] {'['}, StringSplitOptions.RemoveEmptyEntries);
  46. StringCollection dbfiles = new StringCollection();
  47. foreach (string s in files) {
  48. string s1 = s.TrimEnd(null);
  49. s1 = s1.TrimEnd(']');
  50. if (s1.Length > 0) dbfiles.Add(s1);
  51. }
  52. Server svr = Connect();
  53. string name = DecodeString(dbname);
  54. svr.AttachDatabase(name, dbfiles);
  55. }
Add Comment
Please, Sign In to add comment