Auto detect whether code is being executed on localhost [IIS] or ISP web server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BigAl42
    New Member
    • Oct 2009
    • 3

    Auto detect whether code is being executed on localhost [IIS] or ISP web server

    My project involves a large number of ASP pages that reference an Access database. I am testing the system first via IIS before publishing it to the web server.

    The connection string is specific to the database location i.e. C:/inetepub/.../*.mdb etc for IIS testing and //web/content/.../*.mdb etc for the web server. Therefore I have to edit all of the files before publishing, then edit them back to continue with local deevelopment. Aagh!!!

    Is there a way to introduce a simple 'test' into my codee as to where the ASP is running?

    I could then 'if...then...el se...' etc and save loads of time.

    Hope you can help.
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    easiest solution is to have the connection string on a separate file and include it on all the pages that use it with a server-side include. Then just use a different copy of that include file on the local versus the hosted site. Does that make sense? Do you need help coding that?

    Jared

    Comment

    • BigAl42
      New Member
      • Oct 2009
      • 3

      #3
      Thanks jhardman - great idea. I've also been advised to explore server.mappath as a way of detecting the host server.
      I prefer the 'includes' solution because of its apparent simplicity; I've not used includes previously but I am aware of the concept so I'll give it a go.
      Cheers,
      Al.

      Comment

      • BigAl42
        New Member
        • Oct 2009
        • 3

        #4
        I just had a go at <--!includes... etc without much success. I created a new ASP file that simply declares a variable named 'path' then assigned the appropriate filepath to it. Then I used s-s includes in the code of my main page and set the connection string value to 'path'.
        I think I've understood the principal correctly haven't I? It's most likely a lack of experience ony part as I'm relatively new to this and have probably got some syntax wrong somewhere!
        I'll have another go soon.

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          Here is an example, a file called "LAdmin.asp " being used as an include file
          Code:
          <%
          ' FileName="Connection_ado_conn_string.htm"
          ' Type="ADO" 
          ' DesigntimeType="ADO"
          ' HTTP="false"
          ' Catalog=""
          ' Schema=""
          Dim MM_LAdmin_STRING
          MM_LAdmin_STRING = "Provider=SQLOLEDB.1;Password=myPwd;Persist Security Info=True;User ID=myUID;Initial Catalog=myDB;Data Source=.\SQLExpress"
          %>
          from the top of one of my ASP pages:
          Code:
          <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
          <!--#include file="../Connections/LAdmin.asp" -->
          <%
          if request("chkCurrent") <> "" then
          	Set oConn = Server.CreateObject("ADODB.connection")
          	oConn.Open MM_LAdmin_STRING
          Hope this helps.

          Jared

          Comment

          Working...