how to attach sqldatabase with sql server dbms from a form of vb.net

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 4
Reputation: saleemwazir is an unknown quantity at this point 
Solved Threads: 0
saleemwazir saleemwazir is offline Offline
Newbie Poster

how to attach sqldatabase with sql server dbms from a form of vb.net

 
0
  #1
Jul 2nd, 2008
i m final year student of computer engineering and there is problem for me in my final year project.
i want to attach databases to sql server dbms from one of the form of my vb.net application. the idea is that a want to have a button name "Browse" when i click on it brows me to sqldatabases now when i select any sqlserver database file, it automaticall attach to sql server dbms.

inshort i want to attach databases with dbms from my application not from using entrprise manager of sqlserver dbms.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 144
Reputation: sierrainfo is an unknown quantity at this point 
Solved Threads: 9
sierrainfo sierrainfo is offline Offline
Junior Poster

Re: how to attach sqldatabase with sql server dbms from a form of vb.net

 
0
  #2
Jul 5th, 2008
Can you please explain a bit more of what exactly you mean by "attach" to SQL Server.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 4
Reputation: saleemwazir is an unknown quantity at this point 
Solved Threads: 0
saleemwazir saleemwazir is offline Offline
Newbie Poster

Re: how to attach sqldatabase with sql server dbms from a form of vb.net

 
0
  #3
Jul 5th, 2008
Originally Posted by sierrainfo View Post
Can you please explain a bit more of what exactly you mean by "attach" to SQL Server.
I mean if we have a database file e.g data.mdf so if we want to make some some transactions in that database we must have to attach this database to sqlserver. i.e we have to go to ENTERPRISE MANAGER than goto databases and then right click on databases then will go to attach database. so a wizard will start to attach that file to dbms. now i want to do the same funtionalities from my application build in vb.net. so i dont have to use sqlserver to attach database.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 144
Reputation: sierrainfo is an unknown quantity at this point 
Solved Threads: 9
sierrainfo sierrainfo is offline Offline
Junior Poster

Re: how to attach sqldatabase with sql server dbms from a form of vb.net

 
0
  #4
Jul 5th, 2008
Yes--it can be done through VB.Net. You will have to use SQL system stored procedures - sp_detach_db to detach the mdf and ldf file from the server. Once the files are detached-you can copy paste then to a folder. Then use sp_attach_db to attach the mdf and ldf files to the other server and remember to attach the mdf and ldf files on your server too--else the DB will not be available.

You must connect to the SQL Server master database using SQLConnection object and run the stored procedures using SQLCommand object.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 4
Reputation: saleemwazir is an unknown quantity at this point 
Solved Threads: 0
saleemwazir saleemwazir is offline Offline
Newbie Poster

Re: how to attach sqldatabase with sql server dbms from a form of vb.net

 
0
  #5
Jul 5th, 2008
Originally Posted by sierrainfo View Post
Yes--it can be done through VB.Net. You will have to use SQL system stored procedures - sp_detach_db to detach the mdf and ldf file from the server. Once the files are detached-you can copy paste then to a folder. Then use sp_attach_db to attach the mdf and ldf files to the other server and remember to attach the mdf and ldf files on your server too--else the DB will not be available.

You must connect to the SQL Server master database using SQLConnection object and run the stored procedures using SQLCommand object.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Thank u sir!
Sir which methond of sqlcommand object is used to run the above mentioned store procedure?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 4
Reputation: saleemwazir is an unknown quantity at this point 
Solved Threads: 0
saleemwazir saleemwazir is offline Offline
Newbie Poster

Re: how to attach sqldatabase with sql server dbms from a form of vb.net

 
0
  #6
Jul 5th, 2008
sir let we have lms.mdf file store in c:/database folder and it is not attach to sqlserver. and we want to attach it through sp_attach_db store procedure. how i will do that. ie

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

sir in above code line number 4 gives error also what to write in lin 1.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: gbpnkpm is an unknown quantity at this point 
Solved Threads: 0
gbpnkpm gbpnkpm is offline Offline
Newbie Poster

Connection string and attaching Database.

 
0
  #7
30 Days Ago
The Connection string is the usual connection string to the database server you want to attach. For example
  1. "Data Source=SQLSERVERNAME; INITIAL CATALOG=master; uid=sa; pwd=sa;".
.You need to add physical path name of MDF and LDF Files in the sp_attach_db sp. You have used three double quotes which will result in some syntax exception.
Try this:

  1. cmd.CommandText = "sp_attach_db 'c:\databases\lms.mdf', 'c:\databases\lms.ldf'"

Happy coding...
Last edited by gbpnkpm; 30 Days Ago at 5:23 am.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC