How is it right to connect the OBD?



  • I'll make a mistake.

    System.Data.SqlClient.SqlException (0x80131904): An attempt to attach an auto-named database for file 😄 \Users/dayover/visual studio 2015/Projects/TestApp/TestDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

       @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C: \Users\dayover\documents\visual studio 2015\Projects\TestApp\TestApp\TestDB.mdf;Integrated Security=True";
    

    Looking online, writing:

    Data Source=.\SQLEXPRESS;Database=myuniquedb;AttachDbFilename=|DataDirectory|\Base.mdf;Integrated Security=True;User Instance=True
    

    I'm making a mistake:

    System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

    The path was taken from: the observator of the TERM base - the Self-Information Connection line.



  • The error means that the testDB database already exists.

    The mechanism for connecting the bases through AttachDbFilename is unreliable (i.e., whether the base is connected or not). Don't use it. Or at least clearly put the name in the connection line. Apparently, with the name of the instas, you guessed, so you only have to ask the very name of the base, like Cat Initialalog or Database:

    Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=mydatabase;AttachDbFilename=C: \Users\dayover\documents\visual studio 2015\Projects\TestApp\TestApp\TestDB.mdf;Integrated Security=True
    

    or

    Data Source=(LocalDB)\MSSQLLocalDB;Database=mydatabase;AttachDbFilename=C: \Users\dayover\documents\visual studio 2015\Projects\TestApp\TestApp\TestDB.mdf;Integrated Security=True
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2