.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

Programmatically attaching database

Posted By: susant     Posted Date: December 12, 2008    Points:2   Category :Sql Server
Is there any way, where i can create a setup file (.net), so that on running setup it should attach database to existing sql server...

Note: Programmatically attaching database

Author: Amit Mehra             
Posted Date: December 12, 2008     Points: 5   

You can use SQL Server Management for that you have to add reference dll by right click on the solution Explorer.


After that

Server SQLServerInstance = new Server("YourServer\\AndInstance");

and so on..you have to explore i didnt explore much on this.

Another way you can find the existing Database by Simple SQL Query to master DataBase

For eg

IF db_id(''''YorDBName'''') IS NOT NULL
'''' If Logic goes here
'''' Else Logic goes here

Or your SQL Query could be like this

select * from master.dbo.sysdatabases where name = ''YourDBName''

And after that for attaching database you can simply use

use 'DataBaseName'

Then proceed your SQL Further query like creating Table,Stored procedure, Update table etc

Please "Mark As Answer " if this post help you.

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend