Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to use function include file for the connection to database

    hi i am a student now doing the system and facing the pobrem for the connection to database.

    because now i am usung the connection like :-
    set conJ=server.CreateObject("ADODB.Connection")
    set rsJ=server.CreateObject("ADODB.Recordset")
    cnJ = "Driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;database=gm"
    strSQLJ="SELECT * FROM number WHERE ctype='GR'"
    rsJ.open strSQLJ, cnJ

    in all of my form.So when i need to change the connection then i need changing all of my form in my system.So have some easy way to solute this problem??For example using the function (include file) then the such connection will save in 1 file 1st?So do you all have some easy sample for that!So if got please reply me ok???

    So thank you 1st for anyone read this message!

  • #2
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    1) Create a new file called global.asa and put the code below in it.
    Code:
    <SCRIPT LANGUAGE=VBScript RUNAT=Server>
    Sub Application_OnStart()
    Application("ConnectionString") = "Driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;database=gm"
    End Sub
    </SCRIPT>
    2) When you need to open a connection, use the following code:
    Code:
    Dim objCon
    Set objCon = Server.CreateObject("ADODB.Connection")
    objCon.Open Application("ConnectionString")

  • #3
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    If you don't use the global.asa file, then put this on a page by itself, with no other code, and no html. Name it connection.asp
    Code:
    <%
    cnJ = "Driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;database=gm"
    %>

    now to use it just add this line of code on each page that you make the connection.
    <!--#include file="connection.asp" -->
    This line cannot be within the asp delimiters. (<% %>)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •