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.

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.

Leave that empty then, just change the rest.

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.

Remove .mdf and fill in your user id.

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

What user id should i give ..

The one you entered when installing SqlExpress.

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 meeting, networking, learning, and sharing knowledge.