I am using VS2010 and created a database using SQL server residing in VS2010. the database is stored in the folder APP_DATA with an extension .mdf

My PC name is rvivek and it resides in a domain. below is my connection string.

myConnection = New SqlConnection("server=rvivek; uid=; pwd=; database=Database1.mdf;")

when i run my program i am getting the below error.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.

Kindly advice how to specify the server name. and also i've not given any username and password for the database. kindly help me.

Recommended Answers

using SQL server

Since you are using SQL Server you need to provide a user id and password too. The database name should be Database1 if that is the name. You are trying to open it like an Access file, that is not possible. Server name could also …

Jump to Post

Leave that empty then, just change the rest.

Jump to Post

You are sure that you have SQL Server (or SQL Express) running on your local machine?

Jump to Post

All 11 Replies

using SQL server

Since you are using SQL Server you need to provide a user id and password too. The database name should be Database1 if that is the name. You are trying to open it like an Access file, that is not possible. Server name could also be localhost in your case, or your IP address.

I've not given any password while creating database.

myConnection = New SqlConnection("server=localhost; uid=; pwd=; database=Database1.mdf;")
myCommand = New SqlCommand(strSQL, myConnection)
myConnection.Open()
MsgBox("Connection Open")

this is my code. My database is available in the APP_DATA folder. even now same problem exists.

Kindly help

You are sure that you have SQL Server (or SQL Express) running on your local machine?

i am having sql express in my local machine.

myConnection = New SqlConnection("server=localhost; uid=rvivek; pwd=; database=Database1;")

What user id should i give ..

i,ve forgotten the user name what i've given at the time of installing. Is there any way to find out.

Try using

connectionString="Data Source=|DataDirectory|\Database1.mdf

Be a part of the DaniWeb community

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