SQL Server Performance

How to attach a db by code?

Discussion in 'Getting Started' started by VeraJordao, May 25, 2007.

  1. VeraJordao New Member

    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.
  2. ranjitjain New Member

    read about sp_attach_db and sp_detach_db in BOL for more information
  3. FrankKalis Moderator

    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
  4. VeraJordao New Member

    In fact I want to know how to attach a db from a VB app.
  5. FrankKalis Moderator

    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>
  6. VeraJordao New Member

    Ok, thanks.....
    I thought it'd have another way....
    I'm going to check sp_attach_db and sp_detach_db.
  7. Adriaan New Member

    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.

Share This Page