Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am attaching My DB through vb.net code. Now I request help for the following:

1) How to detach it using code (uid=sa, pwd=abc123)?
2) How to take backup?
3) How to restore backup?

Please note I want to do it all using vb.net code

Thanks a lot.
Posted

1 solution

backup and restore program

Backup & Restore of SQL Server database using VB.NET[^]


Attach and detach program



1: conn.connectionstring = ?
2: conn.open
3: cmd.CommandType = CommandType.StoredProcedure
4: cmd.CommandText = "sp_attach_db "lms' "
5: cmd.connection=conn
6: cmd.executenonquery


connection string using username and pass

"Data Source=SQLSERVERNAME; INITIAL CATALOG=master; uid=sa; pwd=sa;".

Hope this helps if yes then accept and vote the answer otherwise revert back with your answer
--Rahul D.
 
Share this answer
 
Comments
Furqan Sehgal 12-Feb-12 2:49am    
It is good but I am looking for something that could run on SQL Server Express also. Thanks any way.
Furqan Sehgal 12-Feb-12 3:09am    
Tried following to detach, Dim conn2 As New SqlConnection("Server=MyHomeServer\SQLExpress;Database=master;Trusted_Connection=False;User ID=sa;Password=abc123;")
Dim cmd2 As New SqlCommand("", conn2)
cmd2.CommandType = CommandType.StoredProcedure
cmd2.CommandText = "sp_detach_db 'MyHomeDBTestPWD'"
conn2.Open()
cmd2.Connection = conn2
cmd2.ExecuteNonQuery()

Error:
Could not find stored procedure 'sp_detach_db 'MyHomeDBTestPWD''.

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