Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 478 Vote(s) - 3.41 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'instance failure' error while connection string is correct

#1
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][1] 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.


[1]:

[To see links please register here]

Reply

#2
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... :)
Reply

#3
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...
Reply

#4
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!
Reply

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

#6
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
Reply

#7
[![I shared an image for figure out the issue on my EF Core 3.0 in a Separate Class Library. ][1]][1]
The root cause is Regular literal ("Backslash: \\") and Verbatim literal ("@"Backslash: \"") .
Reference

[To see links please register here]


[1]:
Reply

#8
Your answer lies in the connected services. edit provider and select the three dots once you find your database select advanced in the advanced you will see your connection string which looks like below.

Data Source=Server\\ServerInstance;Initial Catalog=yourDatabaseName;Integrated Security=True

You can add more services and configure more there.
Reply

#9
I have the following connection:

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

My server's identifier is: `MyComputerName\SQL2012ENTERPRS`

But since I'm use a string, I add another blackslash `\` so the string becomes:

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

I have forgotten that I must remove one of `\` since I am not use the default string block, I use an XML file to save my connection string and then everything is okay so my suspicion is that your instance name is not correct.

This is my connection string it I use on a local pc using SQL
Express:

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

You should modify the above string with your server name and instance name and ensure it is correct.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through