i'm creating an small application which uses sqlConnection for the purpose of connection to the database.
but i'm not able to connect to the server

the error is:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

my code is: ConnString = "Data Source=(HOME\SQLEXPRESS);Initial Catalog=college;Integrated Security=True" here ConnString is the connection string, college is my sql database.

the error is displayed when i try to open the connection to the database.

please tell me how to write the correct connection string (i want to access the database through windows authentication)

Recommended Answers

All 6 Replies

Can you show more code, beacuse I do not see the connection object something like this

Dim conn as New System.Data.SqlClient.SqlConnection(ConnectionString)

and then

conn.open()

You have a problem with connection string. Verify your database connection with Server Explorer of Visual Studio 2005/2008.

Data Source=.\SQLEXPRESS;Initial Catalog=college;Integrated Security=True;

i have obtained solution to my problem as follows and its working properly.

Public Conn As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\college.mdf;Integrated Security=True;User Instance=True")

Note: I have placed database in Debug folder of my project.

Respected adatapost, i want to know if i will use your connection string ie:

Data Source=.\SQLEXPRESS;Initial Catalog=college;Integrated Security=True;

then, where should i place my db.
please reply.
waiting for ur reply.

i have obtained solution to my problem as follows and its working properly.

Public Conn As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\college.mdf;Integrated Security=True;User Instance=True")

Note: I have placed database in Debug folder of my project.

Respected adatapost, i want to know if i will use your connection string ie:

Data Source=.\SQLEXPRESS;Initial Catalog=college;Integrated Security=True;

then, where should i place my db.
please reply.
waiting for ur reply.

Your database is a local sql server database. To convert local database into remote database - Use attach database feature available with Server Explorer + Add New Connection + Microsoft Sql Server + Checked Attach a database file and assign logical name "college".

try to connect with the username and password(ie, with the sql authentication mode).your poblem will be solved surely

Actually, your issue is not so much about the connection string in this instance. The issue is within the setting of SQL Express!

I no longer have sql express loaded so, I apologize if my reply appears rather vague - but it should point you in the right direction.

I think you need to go into the management consol and turn on/allow tcp/ip or something like that.

Have a look at the default settings in other words and allow tcp/ip -that allows the remote connection to be allowed to establish a connection, using your connection string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.