Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I'm developing a VB.net application .. and when I try to connect to the databse I get this error; Itry many solution but nothing is working well with me ..Any Idea?

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)
Posted
Comments
Zoltán Zörgő 5-Oct-12 13:23pm    
First of all, are you able to connect to the same database from the same computer using SQL Server Manager for example?

Probably, you have a problem with your connection string.
First off, try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.

Your connection should now work.
 
Share this answer
 
You havn't created a instance of SQL server (management studio),first complete your installation and then go for connection .if its their then, how you are making connection with Database ?can u post your code.so i can give you exact idea.:-)
 
Share this answer
 
v2
Comments
Lotus90 5-Oct-12 14:22pm    
Imports System.Data.SqlClient
Imports System.Data
Dim con As New SqlConnection("Data Source=D:\Users\Reema\Documents\Test.sdf")
Dim cmd As SqlCommand
Dim dr As SqlDataAdapter
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click


If TextBox2.Text <> "" And TextBox3.Text <> "" Then

con.Open()
cmd.CommandText = "insert into test(id , name ) VALUES (' " & TextBox2.Text & " ','" & TextBox3.Text & " ')"
cmd.ExecuteNonQuery()
con.Close()

End If
End Sub
[no name] 5-Oct-12 14:31pm    
Your connection string is all wrong.
Lotus90 5-Oct-12 15:22pm    
Then what I have to do ?!
as per discussion in solution-2,
connection string is wrong.

sql connection string should be like below,

if sql server have Windows authentication Mode
"data source=ServerName; Initial Catalog=DatabaseName; Integrated security=true;"


if sql server have SQL authentication Mode
"data source=ServerName; Initial Catalog=DatabaseName; Uid=SQLServerLoginId;pwd=SQLServerPassword;"


Happy Coding!
:)
 
Share this answer
 
Comments
Jithu Wilson C 11-Aug-16 7:43am    
The same error happens after changing computer name. The above solution is not possible for me.

Dim cn As New SqlConnection("Data Source=JITHU-PC;Initial Catalog=vbsql;Integrated Security=True")
Firewall is OK
TCP/IP Port is OK.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900