Click here to Skip to main content
15,945,119 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying already two days to connect my application to database. I built c# applictaion which works correctly. Now i want to use this app second machine. I installed sql server r2 put database .mdf and log file into data folder. changed connection string my app but it cannot connect to database. Data Source=.\SQLEXPRESS;Initial Catalog=Med;Trusted_Connection=True this is con string. If i change database name(Med) with Master connection is succesfull. Am i must install sql server managmet studio? Without it i cannot connect? Can anyone help me?
Posted

Do you mean you have only copied the database files for the Med db to data directory. If that's the case, it's not enough. You have to 'register' the database to the SQL Server instance. One option is that you take a backup on the original server and restore the backup in target server. Another option is to detach the database at source and then attach it at target machine.

More info:
- http://msdn.microsoft.com/en-us/library/ms177429.aspx[^]
- http://msdn.microsoft.com/en-us/library/ms190794.aspx[^]
 
Share this answer
 
Comments
fjdiewornncalwe 11-Aug-11 10:18am    
What I was thinking as well. +5.
Wendelius 11-Aug-11 10:30am    
Thanks :)
lester555 11-Aug-11 10:19am    
thanks for replay. I know it need to be attached but i cannot install managment studio how i can attach without managment studio or is there any light software for attaching?
Wendelius 11-Aug-11 10:24am    
You can do this also by using sp_attach_db and sp_detach_db procedures. You can use for example sqlcmd command line utility to execute sql statements against the SQL Server. See: http://msdn.microsoft.com/en-us/library/ms162773.aspx[^]
Try this in VS:
1) Open the Server Explorer pane
2) If your database is not listed, right click on "Data Connections" and select "Add Connection..." Follow the steps to add your DB.
3) Click on your database name to highlight it.
4) Look at the Properties pane - it will contain the connection string.
5) Right click the string, "Select All", Right click "Copy"
6) Paste the string into your program (or preferably use an application setting string so it is easy to change) and try that.
 
Share this answer
 

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



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