| | |
how to attach sqldatabase with sql server dbms from a form of vb.net
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2008
Posts: 4
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Jul 2008
Posts: 4
Reputation:
Solved Threads: 0
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.
•
•
Join Date: May 2008
Posts: 144
Reputation:
Solved Threads: 9
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.
You must connect to the SQL Server master database using SQLConnection object and run the stored procedures using SQLCommand object.
•
•
Join Date: Jul 2008
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
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?
•
•
Join Date: Jul 2008
Posts: 4
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
The Connection string is the usual connection string to the database server you want to attach. For example
.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:
Happy coding...
VB.NET Syntax (Toggle Plain Text)
"Data Source=SQLSERVERNAME; INITIAL CATALOG=master; uid=sa; pwd=sa;".
Try this:
VB.NET Syntax (Toggle Plain Text)
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.
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: mdi child maximize, form tiling, and alignment of controls
- Next Thread: Server Name to connect to an online database?
| Thread Tools | Search this Thread |
.net .net2008 2008 access add advanced application array basic beginner browser button buttons center click code combo cpu cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic employees excel exists fade filter forms generatetags html images input intel internet listview map mobile module monitor msaccess mysql net number objects open pan panel pdf picturebox picturebox2 port position print printing printpreview problem regex reuse right-to-left save search searchvb.net serial settings shutdown socket sqldatbase sqlserver storedprocedure survey temperature textbox timer timespan transparency txttoxmlconverter user usercontol vb vb.net vba vbnet vista visual visualbasic visualbasic.net visualstudio.net web winforms wpf wrapingcode xml year





