OLEDB Connection String

Discussion in 'ASP General' started by MasterChief, Dec 16, 2005.

  1. MasterChief

    MasterChief Guest

    I have a OLEDB Connection String that is working very well for me. My
    question is that I read that you can store the Connection String in a
    seperate include file or somewhere else. I am just wondering where is
    the proper place to store this Connection String and how do I call it
    from my application.
    My Example is below

    Set Conn = Server.CreateObject("ADODB.Connection")
    Set Rs = Server.CreateObject("ADODB.RecordSet")
    Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
    Catalog = TestSQL; User Id = sa; Password = test"
    sSQL = "SELECT * FROM Html ORDER BY HtmlName ASC"
    Set Rs = Conn.Execute(sSQL)
    Do While NOT Rs.EOF
    Rs.MoveNext
    Loop
    Rs.Close
    Set Rs = Nothing
    Conn.Close
    Set Conn = Nothing

    Would the answer be to put
    Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
    Catalog = TestSQL; User Id = sa; Password = test"
    into an asp page and then use <!--#include file="test.asp"-->
    like

    Set Conn = Server.CreateObject("ADODB.Connection")
    Set Rs = Server.CreateObject("ADODB.RecordSet")
    <!--#include file="test.asp"-->
    sSQL = "SELECT * FROM Html ORDER BY HtmlName ASC"
    Set Rs = Conn.Execute(sSQL)
    Do While NOT Rs.EOF
    Rs.MoveNext
    Loop
    Rs.Close
    Set Rs = Nothing
    Conn.Close
    Set Conn = Nothing
    MasterChief, Dec 16, 2005
    #1
    1. Advertising

  2. MasterChief wrote:
    > I have a OLEDB Connection String that is working very well for me. My
    > question is that I read that you can store the Connection String in a
    > seperate include file or somewhere else. I am just wondering where is
    > the proper place to store this Connection String and how do I call it
    > from my application.
    > My Example is below
    >

    <snip of irelevant code>
    > Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
    > Catalog = TestSQL; User Id = sa; Password = test"


    I hope you are not really using the sa account for your application code ...
    and that the password is not really "test".

    <snip of irelevant code>
    >
    > Would the answer be to put
    > Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
    > Catalog = TestSQL; User Id = sa; Password = test"
    > into an asp page and then use <!--#include file="test.asp"-->


    That's one way. I ususally create a function in the include file that
    returns the connection string:

    <%
    function GetConnectString()
    GetConnectString="<your connection string>"
    end function
    %>

    Then
    <!--#include file="test.asp"-->
    <%
    dim sConnect
    sConnect=GetConnectString
    ....
    Conn.Open sConnect
    %>

    Using a function allows you to add arguments to control which connection
    string to return if you have multiple strings that could be used (perhaps a
    test vs production environment). You could also use the server_name
    servervariable to control which connection string gets returned.

    Equally valid is using an application variable to store the string,
    initializing it in the application_onstart event in global.asa.

    Bob Barrows
    --
    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], Dec 16, 2005
    #2
    1. Advertising

  3. MasterChief

    MasterChief Guest

    Yes you are correct about the password and such. I just wanted to throw
    up an example really fast. Thank you for your help.
    > I hope you are not really using the sa account for your application code ...
    > and that the password is not really "test".
    >
    > <snip of irelevant code>
    > >
    > > Would the answer be to put
    > > Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
    > > Catalog = TestSQL; User Id = sa; Password = test"
    > > into an asp page and then use <!--#include file="test.asp"-->

    >
    > That's one way. I ususally create a function in the include file that
    > returns the connection string:
    >
    > <%
    > function GetConnectString()
    > GetConnectString="<your connection string>"
    > end function
    > %>
    >
    > Then
    > <!--#include file="test.asp"-->
    > <%
    > dim sConnect
    > sConnect=GetConnectString
    > ...
    > Conn.Open sConnect
    > %>
    >
    > Using a function allows you to add arguments to control which connection
    > string to return if you have multiple strings that could be used (perhaps a
    > test vs production environment). You could also use the server_name
    > servervariable to control which connection string gets returned.
    >
    > Equally valid is using an application variable to store the string,
    > initializing it in the application_onstart event in global.asa.
    >
    > Bob Barrows
    > --
    > 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"
    MasterChief, Dec 16, 2005
    #3
    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. Mathew Vording

    asp.net ms-access oledb connection open error

    Mathew Vording, Aug 15, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,169
    Mathew Vording
    Aug 15, 2003
  2. Louise Hadley

    OLEDB database connection from ASP.NET

    Louise Hadley, Apr 16, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    7,502
    Louise Hadley
    Apr 17, 2004
  3. =?Utf-8?B?Uk1M?=

    MS Access OLEDB connection problem

    =?Utf-8?B?Uk1M?=, Jul 21, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    3,257
    =?Utf-8?B?Uk1M?=
    Jul 24, 2004
  4. Replies:
    0
    Views:
    609
  5. =?Utf-8?B?VGltOjouLg==?=

    OleDB Connection Problem to Access DB...

    =?Utf-8?B?VGltOjouLg==?=, Jun 15, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    441
    =?Utf-8?B?VGltOjouLg==?=
    Jun 15, 2006
Loading...

Share This Page