Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Concept of creating or attachind DB to the instanc

Author  Topic 

kfsehgal
Starting Member

6 Posts

Posted - 2012-02-10 : 09:43:57
Hi,
I have a SQL Server DB which I can attach manually using SSMS and application works fine after this. I want to make the process automatic, i.e do not want my clients to use SSMS to attach DB but I want my application to do it at first time run or during installation. But I have no idea at all how to do it. Many people suggested code snippets but I donot know where to put them.
I have seen a concept of SQLDMO but could not find over google how to make and use them in vb.net.

I tried the code

Dim conn As New SqlConnection("Server=(local);Data Source=;Integrated Security=SSPI")
Dim cmd As New SqlCommand("", conn)

cmd.CommandText = "CREATE DATABASE MyDBTest ON ( FILENAME = 'D:\dbSQLTest.mdf' ), ( FILENAME = 'D:\dbSQLTest_log.ldf' ) FOR ATTACH"

conn.Open()

cmd.ExecuteNonQuery()

cmd.Dispose()
conn.Dispose()

Unable to open the physical file "D:\.Net Programs\AttachDBProg\AttachDBProg\dbSQLTest.mdf". Operating system error 5: "5(failed to retrieve text for this error. Reason: 15105)".

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-10 : 11:09:28
see below

http://www.codeproject.com/Articles/10032/Deploy-SQL-Server-databases-easily-with-an-Install

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -