Please tell me how can we attach SQL Server database (SQL Server 2005) during installation or after installation using c#.net (desktop application). We can create a form to get details of connection string (user id, pass, server name etc..) . please tell me how can we automatically attach database with SQL Server using .net
-
please don't put tags like " (c#.net)" in the title. Please leave them in the tags.John Saunders– John Saunders2010-06-09 06:52:41 +00:00Commented Jun 9, 2010 at 6:52
-
You cannot "attach" a SQL Server database (except for the SQL Server Express version). You create a database and then your software connects to that database.marc_s– marc_s2010-06-09 07:27:16 +00:00Commented Jun 9, 2010 at 7:27
Add a comment
|
3 Answers
Execute a full create database script with your tables, SPs etc. the same way you do any insert i.e. call ExecuteNonQuery method.
Is it what you were asking or you need something more?
2 Comments
Dr. Rajesh Rolen
its a good idea.. but i was asking about attaching database programmatically
IsmailS
Do you mean that you already have .mdf file and you want to attach it?
This way you will an app.config setting for automatic Db Attach as well :