'instance failure' error while connection string is correct

57,044

Solution 1

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... :)

Solution 2

I have connection:

Data Source=MyComputerName\SQL2012ENTERPRS;Initial Catalog=RESTFUL; User Id=myuser; Password=mypass123;

My server is : MyComputerName\SQL2012ENTERPRS

But since I use string, I add more \ so, at my code It will be:

public string connectionString = "Data Source=DAFWKN409C67Q\\SQL2012ENTERPRS;Initial Catalog=RESTFUL; User Id=rest_user; Password=rest_pwd_01;";

I have forgoten that I must remove one of \ since I am not use default string block, I use XML file to save my connection string. Then everything is ok. So, my suggestion is your instance name is not correct.

This is my connection string sample it I use local pc using SQL express:

string servername = @"Data Source=.\SQLExpress;Initial Catalog=Workshop;Integrated Security=True";

You should modify with your server name, and instance name by yourself, make sure it correct.

Solution 3

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!

Solution 4

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

Solution 5

I shared an image for figure out the issue on my EF Core 3.0 in a Separate Class Library. The root cause is Regular literal ("Backslash: \") and Verbatim literal ("@"Backslash: \"") . Reference https://csharpindepth.com/Articles/Strings

Share:
57,044

Related videos on Youtube

C Sharper
Author by

C Sharper

Updated on July 09, 2022

Comments

  • C Sharper
    C Sharper almost 2 years

    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 SqlConnection("Data Source=14GRAFICALI\\SQLEXPRESS;Initial Catalog=sagar;Integrated Security=True")
            '-----------------------fill name ddl------------------------------'
    
            Try
    
                da = New SqlDataAdapter("select EmpName from empMaster_VB", con)
                ds = New DataSet()
                da.Fill(ds)
                For i As Integer = 0 To ds.Tables(0).Rows.Count
    
                    ddlName.Items.Add(ds.Tables(0).Rows(i)(0).ToString())
    
                Next
    
    
            Catch ex As Exception
    
            End Try
    
            '--------------------------------------------------------------------'
    
    
            '----------------fill expence-------------------------------------'
    
            Try
    
                da = New SqlDataAdapter("select ExpName from expenceType_VB", con)
                ds = New DataSet()
                da.Fill(ds)
                For i As Integer = 0 To ds.Tables(0).Rows.Count
    
                    ddlExpence.Items.Add(ds.Tables(0).Rows(i)(0).ToString())
    
                Next
    
    
            Catch ex As Exception
    
            End Try
    
    
            '---------------------------------------------------------------'
    
    
    
        End Sub
    

    This code is to fill drop downs with names and expence values in database tables.

    I am getting 'instance failure' error while executing the code.

    I checked one of the answers on stack and checked my connection string. But, my connection string is also correct.

    Please help me if anything else is missing in this code.

    • Milen
      Milen almost 11 years
      Are you opening the connection?
    • C Sharper
      C Sharper almost 11 years
      no, i am not opening the connection
    • Milen
      Milen almost 11 years
      add con.Open() before you do the Select statement
    • C Sharper
      C Sharper almost 11 years
      i removed // from datasource and made / and it worked.
  • Vidhya Sagar Reddy
    Vidhya Sagar Reddy almost 11 years
    Try restarting your instance once.. :)
  • Vidhya Sagar Reddy
    Vidhya Sagar Reddy almost 11 years
    That could even work for .\SQLEXPRESS if the machine is local... :)
  • C Sharper
    C Sharper almost 11 years
    yup, // was issue. it worked on both, only i was not removing // and making it / . Thanks
  • Jimmy Shaw
    Jimmy Shaw about 7 years
    Perfect solution. My connectionString previously was "Server=OWNER-PC\\SQLEXPRESS" and got Instance Failure after using EF6's update-database command. After changing it to "Data Source=.\SLQEXPRESS" all works great.
  • JMIII
    JMIII about 6 years
    Was having issue with NLog and database target and this solved!
  • Gagan
    Gagan about 5 years
    I was having the same problem and this answer worked for me, I removed the double \\ in the data source name to a single \
  • Zonus
    Zonus almost 5 years
    I didn't update my exe configuration file and some how this got updated with two back slashes. I checked my source control and it was a single slash up until this started happening. You were right on the money; thanks.
  • Tushar Kshirsagar
    Tushar Kshirsagar over 4 years
    this worked for me, many time in c# code we pur @ then there is no need of \\ just use \ if @ is preceding the connection string.
  • Eternal21
    Eternal21 almost 4 years
    Worked like a charm. Two slashes were fine in ASP.NET Core project, but crashed in plain ASP.NET.