468,512 Members | 1,504 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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...else...' etc and save loads of time.

Hope you can help.
Oct 10 '09 #1
4 2726
3,405 Expert 2GB
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?

Oct 12 '09 #2
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.
Oct 12 '09 #3
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.
Oct 12 '09 #4
3,405 Expert 2GB
Here is an example, a file called "LAdmin.asp" being used as an include file
Expand|Select|Wrap|Line Numbers
  1. <%
  2. ' FileName="Connection_ado_conn_string.htm"
  3. ' Type="ADO" 
  4. ' DesigntimeType="ADO"
  5. ' HTTP="false"
  6. ' Catalog=""
  7. ' Schema=""
  8. Dim MM_LAdmin_STRING
  9. MM_LAdmin_STRING = "Provider=SQLOLEDB.1;Password=myPwd;Persist Security Info=True;User ID=myUID;Initial Catalog=myDB;Data Source=.\SQLExpress"
  10. %>
from the top of one of my ASP pages:
Expand|Select|Wrap|Line Numbers
  2. <!--#include file="../Connections/LAdmin.asp" -->
  3. <%
  4. if request("chkCurrent") <> "" then
  5.     Set oConn = Server.CreateObject("ADODB.connection")
  6.     oConn.Open MM_LAdmin_STRING
Hope this helps.

Oct 13 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Szafranr | last post: by
8 posts views Thread by Robert Dufour | last post: by
12 posts views Thread by John Kotuby | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.