'instance failure' error while connection string is correct
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
The root cause is Regular literal ("Backslash: \") and Verbatim literal ("@"Backslash: \"") .
Reference https://csharpindepth.com/Articles/Strings
Related videos on Youtube
![C Sharper](https://i.stack.imgur.com/fddXL.png?s=256&g=1)
C Sharper
Updated on July 09, 2022Comments
-
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 almost 11 yearsAre you opening the connection?
-
C Sharper almost 11 yearsno, i am not opening the connection
-
Milen almost 11 yearsadd
con.Open()
before you do the Select statement -
C Sharper almost 11 yearsi removed // from datasource and made / and it worked.
-
-
Vidhya Sagar Reddy almost 11 yearsTry restarting your instance once.. :)
-
Vidhya Sagar Reddy almost 11 yearsThat could even work for .\SQLEXPRESS if the machine is local... :)
-
C Sharper almost 11 yearsyup, // was issue. it worked on both, only i was not removing // and making it / . Thanks
-
Jimmy Shaw about 7 yearsPerfect 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 about 6 yearsWas having issue with NLog and database target and this solved!
-
Gagan about 5 yearsI was having the same problem and this answer worked for me, I removed the double \\ in the data source name to a single \
-
Zonus almost 5 yearsI 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 over 4 yearsthis 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 almost 4 yearsWorked like a charm. Two slashes were fine in ASP.NET Core project, but crashed in plain ASP.NET.