Hi.
I'v created a program with a Ms SQL database, registration form and login form. Everything was working well so i detached the database and added it to my program as an existing item before so as to deploy the program. But now i recieve an error when i try to login to the database. The error states that there is a failure connecting to the database and the database cannot be opened

Recommended Answers

All 10 Replies

Hi.
i detached the database and added it to my program as an existing item

What exactly you did ?

Sounds like you changed the location of the database and the app no longer knows where to find it. check your connectionstring.
Hope this helps...

Can you post the code so that i can see what you have done...

Thanks for the response.
I wanted to deploy the program so that i can install it into another computer. i added the database to my project folder but dont know how to change my connection string so that the program can find the database in the project folder

Ok here is the code for the login form which was working before i detached the database.

conn.ConnectionString = ("Data Source=MY-PC; Initial Catalog = Database;Integrated Security=True")
        conn.Open()

have you attach your database to MS SQL server databases on other computer?
also check you server name in another computer, i mean another computer may have a different server name. it will affect your connection string.

Have you restored the database to a new server or do you want to use the database .mdf file in your project directly?

If this is the case you need to use file datasource

SNIP

You have made a mistake in the connection string
conn.ConnectionString = ("Data Source=MY-PC; Initial Catalog = Database;Integrated Security=True")
conn.Open()

MY-PC is the name of your computer you should not fix the name of your computer as because in this case the PC where you want to deploy your software need to have the same computer name (MY-PC).

Try this connection string this will take the computer name automatically

con = New SqlConnection("Data Source=.\SQLEXPRESS; Initial Catalog=misdata; Integrated Security=SSPI;")
con.Open()

note: SQLEXPRESS IS THE INSTANCE OF SQLSERVER 2005.
if you are using sql server 2000 then let me i will send you another connection string.

http://www.dofactory.com/Connect/Connect.aspx

See this link. Connection String formats for all different type of DB Providers are given. I use this one, because I am accessing a DB server with given IP address .In your case, which is local machine, name of server can be found in your object explorer where you see a tree view of all databases in your sql server

connectionString="Data Source=10.0.22.235;Initial Catalog=sample;User ID=sa;Password=ibs123"

Hey thanks a lot for the responses. The problem was the connection string but now that I'v changed it, it works.
I'v just completed my first program fully functional program. Hurrah!

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.