1

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

2
  • please don't put tags like " (c#.net)" in the title. Please leave them in the tags. Commented 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. Commented Jun 9, 2010 at 7:27

3 Answers 3

3

You can use the SQL Express Edition it attach automatically database.

Sign up to request clarification or add additional context in comments.

Comments

2

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

its a good idea.. but i was asking about attaching database programmatically
Do you mean that you already have .mdf file and you want to attach it?
1

You should add a Service-Based Database to your project as shown: enter image description here This way you will an app.config setting for automatic Db Attach as well : enter image description here
All that you will need to do after that is change the database server instance name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.