Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 15th, 2006, 02:22 PM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to perryml
Default Conditional Connection String Code

Hello everyone. This is my first time posting anything so here goes. I am really new to asp classic. I use vb script as the scripting language. My task is to make the database connection string portable. So no matter WHICH machine the database is sitting on, the connection string will follow. Now each possible server is represented by the IP's address.

I was able to learn the code to determine the IP address and if the IP address is true then the connection string is loaded into the varibale. However in the actual site, everything refers back to a global connction string.

Therefore I am changing this in the 'constants' page. Basically the connection string has been globalized. However the strings will change depending on which IP's address is true.

Here is the code that I am currently working with:
I was thinking of making the Const MCCI Constring a variable that is set by the conditional statements. I am unsure how to do this because I do not know how to assgin an varible to a constant. Please help if you can.

{I had to change some data and connection strings, do not worry about the consistency of the connection string}


<%
    'Declaring Variables
    Dim IP
    Dim Rs
    Dim Conn
    Dim pc

    IP = Request("LOCAL_ADDR")
    Set pc = nothing
    Response.write Request.ServerVariables("LOCAL_ADDR")

    If (IP = "127.0.0.1") then
     'Open ODBC Source
            const MCCIConnectionString = "Provider=sqloledb; server=MDD-MPERRY-S; database=MDD; uid=bisSA;pwd=cuberacle;"

     'IP Address for MD-INT-DEV-02
     'If (IP = "172.16.28.141") then
            'MDConnectionString = "Provider=sqloledb; server=Mdd-INT-dev-02; database=Mtti; uid=sa;pwd=cuberac;e;"

    'IP Address for Production Site
    'If (IP = "172.16.32.56") then
        'cn.Open MdConnectionString

    Else
        'Error Message when the IP address has not been added
        response.write("<h3><b>Please add the ip address of the server to the this page to work</b></h3>")
    End If
%>

<%

'The root path to the bis system (root ip name on the dns server)
Const MCCISiteName = "http://bis/"
Const MCCIRootPath = "http://bis/"
Const MCCIWebRoot = "http://bis/"
Const RootPath = "http://bis/"
'Const ConnectionString = "Provider=sqloledb; server=tick-MPERRY-S; database=tick; uid=bisSA;pwd=cubuncle;"
'Const ClientData = "\\md-int-fp-01\BIS\ClientData"
Const TempCorrespondence = "\\mmd-int-fp-01\mccigeneral\Correspondence Upload\"
Const MemoPath = "\\mmd-int-fp-01\general\Legal Memo Upload\"
Const CareerPath = "\\mmd-int-fp-01\BIS\munibode.com\Applications\"
Const OrdPath = "\\mmd-int-fp-01\BIS\accounts\accts\"
'BIS Documents root path
Const DocumentPath = "\\mmd-int-fp-01\BIS\Accounts\Documents\"
Const VirtualPath = "\\mmd-int-fp-01\BIS\Accounts\"
Const ClientData = "\\mmd-int-fp-01\BIS\mcciclientdata\"



Marvin L. Perry Jr.
 
Old November 15th, 2006, 06:45 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

IMO you should use the machine name and not the IP address. When you think about it the machine name is much less likely to change than the IP. Anyhow, this is not an answer to your question however I hope this gives you an idea how I skin the same cat:

Global Constants file (global.asp):
  DataBaseType = iDT_SQLServer
  const IUSER = "XX"
  const pWord = "XXXXXX"
  const DBNAME = "myDB"
  const DBSERVER = "MachineName"
  const MailEnabled = false
  UseODBC = false
  const URLBase = "http://localhost/rootDir/"
  const DOCBase = "http://localhost/rootDir/Docs/"
  'Amoung other useful global constants plus common variables like:
  dim DatabaseType,Driver,UseODBC,SendingeMail,iRegion,c onn,sql,EoF,getInfo,C_FALSE,C_TRUE
---------------------------------------------------
Global function file (function.asp):
  Function GetConnectionString()
     GetConnectionString = "Provider=SQLOLEDB.1; Password=" & pWord & "; Persist Security Info=True; User ID=" & IUSER & "; Initial Catalog=" & DBNAME & "; Data Source=" & DBSERVER & ";"
  End Function
  (Amoung other useful global functions...)
-------------------------------------------------
Now in the head of every page where a DB connection is needed:

<% OPTION EXPLICIT %>



<% Set Conn = server.createobject("ADODB.Connection")
     conn.open(GetConnectionString)
     sql = "SELECT...;"
     set getInfo = conn.execute(sql)
     ...


Wind is your friend
Matt
 
Old November 22nd, 2006, 11:01 AM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to perryml
Default

Thank you so much for this work around, it really worked. I learned one thing here, and thats ASP does not allow you to do conditional includes. Thank you so much for your help.

Marvin L. Perry Jr.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection string bex BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 4 August 3rd, 2008 02:16 PM
connection string kooky SQL Server ASP 1 February 14th, 2008 09:59 AM
Connection String slgknjn VB Databases Basics 2 February 26th, 2005 03:14 AM
Connection String aadz5 JSP Basics 1 January 24th, 2005 04:36 AM
Connection String JsonTerre1 BOOK: ASP.NET Website Programming Problem-Design-Solution 5 November 1st, 2004 02:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.