'instance failure' error while connection string is correct

后端 未结 7 445
醉梦人生
醉梦人生 2021-01-01 10:01

I have following code on page load event:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        con = New Sq         


        
相关标签:
7条回答
  • 2021-01-01 10:29

    in my case just kick up the double \\ to one slush \ :=)

    0 讨论(0)
  • 2021-01-01 10:29

    Use the wildcard "@" before "Data Source" declaration. someting like this: connetionString = @"Data Source=...

    So you'll be able to use only a back slash. Like this: @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\jcabarros...

    0 讨论(0)
  • 2021-01-01 10:33

    I know this is an old thread, but perhaps a good update. I couldn't find a good answer on the web search.

    I got the same 'Instance Failed' error when trying to reference a DbContext from another project in the same solution. The 1st project had a DbContext and the connection string, and the 2nd project in the solution was trying to reference it. The 1st app ran ok on its own, issue only occurred when running the 2nd app.

    The issue was that the app.config file that had the connection string from the 1st project was not in view/scope of the 2nd project. So the connection string wasn't assembled.

    My solution was to copy the app.config from the first project to the second project.

    This was on VS 2019.

    Hope this helps

    0 讨论(0)
  • 2021-01-01 10:34

    I had this issue because I got the connection string from appsettings.Development.json:

    "Server=msi\\DataBaseName;Database=Super25;Trusted_Connection=True;"
    

    but when I changed to

    "Data Source=msi\DataBaseName;Initial Catalog=Super25;Integrated Security=True;"
    

    solved!

    0 讨论(0)
  • 2021-01-01 10:35

    The root cause is Regular literal ("Backslash: \") and Verbatim literal ("@"Backslash: \"") . Reference https://csharpindepth.com/Articles/Strings

    0 讨论(0)
  • 2021-01-01 10:45

    As you got the error "instance failure", that might be the error with your SQL Server instance..

    Make sure your SQL Server instance(MSSQLSERVER) is running, where you can check in: Services list. TO get into services list: open run dialog box and type: "services.msc" (without quotes) and hit Enter. That takes you to services management console, where you can check whether your instance in running or not..

    If the problem still persists, then try using: Data Source=.\SQLEXPRESS instead.. :)

    Happy Coding... :)

    0 讨论(0)
提交回复
热议问题