ADODB.Connection and SQLEXPRESS

Discussion in 'ASP General' started by Aykut Canturk, Jan 7, 2008.

  1. Can I use SqlExpress2005 AttachDatabase feature with classic ADO connections
    in my .asp pages ? But I need ConnectionString. Although I searched the web
    for couple of weeks I still coulnd't find any solution.

    anybody succeeded to use classic ado with attach feature without attaching
    database filed from enterprise manager ? I want tou use SQL2005 and I don't
    want directly attch files to sql.

    Best regards...

    <%
    set cn = Server.CreateObject("ADODB.Connection")

    ' THIS ConnectionString IS WRONG of course. I need correct and working one

    ConnectionString=
    "Provider=SQLNCLI;Server=.\SQLExpress;AttachDbFilename=c:\db\mydbfile.mdf;Trusted_Connection=Yes;"

    cn.open ConnectionString

    ..... database operations....

    cn.execute sqlstr

    cn.close
    set cn = nothing
    %>
     
    Aykut Canturk, Jan 7, 2008
    #1
    1. Advertising

  2. Aykut Canturk wrote:
    > Can I use SqlExpress2005 AttachDatabase feature with classic ADO
    > connections in my .asp pages ?


    I've never done it, but it is supposedly possible

    > But I need ConnectionString. Although I searched
    > the web for couple of weeks I still coulnd't find any solution.
    >
    > anybody succeeded to use classic ado with attach feature without
    > attaching database filed from enterprise manager ? I want tou use SQL2005
    > and I
    > don't want directly attch files to sql.
    >
    > Best regards...
    >
    > <%
    > set cn = Server.CreateObject("ADODB.Connection")
    >
    > ' THIS ConnectionString IS WRONG of course. I need correct and
    > working one
    > ConnectionString=
    > "Provider=SQLNCLI;Server=.\SQLExpress;AttachDbFilename=c:\db\mydbfile.mdf;Trusted_Connection=Yes;"
    >


    From www.connectionstrings.com:
    *************************************************************************
    Attach a database file on connect to a local SQL Server Express
    instance:

    Driver={SQL Native
    Client};Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;
    Database=dbname;Trusted_Connection=Yes;

    Why is the Database parameter needed? If the named database have
    already been attached, SQL Server does not reattach it. It uses the attached
    database as the default for the connection.

    Attach a database file, located in the data directory, on connect to a
    local SQL Server Express instance:

    Driver={SQL Native
    Client};Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;
    Database=dbname;Trusted_Connection=Yes;

    Why is the Database parameter needed? If the named database have
    already been attached, SQL Server does not reattach it. It uses the attached
    database as the default for the connection.
    *************************************************************************

    FWIW, I've had issues connecting to SQL 2005 databases from ASP using
    trusted connections. I have had to create a SQL login and use it in my
    connection strings.

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Jan 7, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. olduncleamos

    Visual Studio 2005 and SqlExpress

    olduncleamos, Jul 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    421
    Juan T. Llibre
    Jul 22, 2005
  2. John
    Replies:
    3
    Views:
    7,836
    Darkonekt
    Oct 16, 2006
  3. dgk
    Replies:
    2
    Views:
    377
  4. Steve Kershaw
    Replies:
    1
    Views:
    383
    Raymond Basque
    Mar 9, 2007
  5. =?Utf-8?B?bXVzb3NkZXY=?=

    IIS7 on Vista and SQLExpress problem

    =?Utf-8?B?bXVzb3NkZXY=?=, Sep 6, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    507
    Steven Cheng[MSFT]
    Sep 14, 2007
Loading...

Share This Page