How to attach a db by code? | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

How to attach a db by code?

I’d like to know how to attach a db by code. In my case, it’s a VB app to be attached to a SQL 2000 db.
read about sp_attach_db and sp_detach_db in BOL for more information
quote:Originally posted by VeraJordao I’d like to know how to attach a db by code. In my case, it’s a VB app to be attached to a SQL 2000 db.
Not sure if I understand you. Are you asking how to attach a db from VB or how to connect to a db from VB? —
Frank Kalis
Microsoft SQL Server MVP
Contributing Editor, Writer & Forum Moderatorhttp://www.sql-server-performance.com
Webmaster:http://www.insidesql.de
In fact I want to know how to attach a db from a VB app.
In that case you already have your answer. See ranjitjain’s reply. [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br />–<br />Frank Kalis<br />Microsoft SQL Server MVP<br />Contributing Editor, Writer & Forum Moderator<a target="_blank" href=http://www.sql-server-performance.com>http://www.sql-server-performance.com</a><br />Webmaster:<a target="_blank" href=http://www.insidesql.de>http://www.insidesql.de</a>
Ok, thanks…..
I thought it’d have another way….
I’m going to check sp_attach_db and sp_detach_db.
Just to make it clear – sp_attach_db is a procedure that takes an existing (series of) MDF file(s) and serves it as a database. sp_detach_db makes the server stop serving the database, and releases (but not deletes) all the attached files. If you want to "attach" tables and views from the database "to" your VB application, then you’re talking about building an interface between the application and the database. You do this by using libraries like ADO in the VB code.
]]>