Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi,
I need to attach my database, that resided in the MyData directory of my application folder, to the instance of SQL server on client's machine. How to do it?

Could any body give me vb.net code for that so my application does it when run for the first time?

Thanks
Posted
Updated 3-Feb-12 5:46am
v3

Try this, this may helps you

Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;


See here for more ...

http://connectionstrings.com/sql-server-2008[^]

Thanks
--RA
 
Share this answer
 
Comments
Furqan Sehgal 3-Feb-12 11:34am    
I am sorry, I put my question wrongly. Actually I need to Attach my DB to the Server instance of the SQL Server Express 2005, programmatically. How to do that?
Thanks
I want to redirect you on this. Have read and revert back with your stuck

http://www.daniweb.com/software-development/vbnet/threads/84306[^]
 
Share this answer
 
Well, you need to use ADO.NET. Please see:
http://en.wikipedia.org/wiki/ADO.NET[^],
http://msdn.microsoft.com/en-us/library/aa286484.aspx[^].

See also: http://www.devlist.com/ConnectionStringsPage.aspx[^].

For starters, I advise this CodeProject article: Using ADO.NET for beginners[^].

Good luck,
—SA
 
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