?
Solved

How do I store and read a Connection String in a config file?

Posted on 2006-05-23
8
Medium Priority
?
247 Views
Last Modified: 2008-02-26
I am trying to store a connection string in a file so I can call the same connection string from many asp pages.  Can anybody help  me with this?  I am new to ASP.
0
Comment
Question by:Flower11
8 Comments
 
LVL 9

Accepted Solution

by:
HappyFunBall earned 1000 total points
ID: 16745733
You'll want to store it in the global.asa page.  Here's a good tip on the subject:  http://www.devx.com/tips/Tip/13180
0
 
LVL 12

Expert Comment

by:Preece
ID: 16746183
Here is how I do it:

1)  I create an include folder and put include files in it.  One such file I call cs.asp.  It may look something like:

<%
  strConnect1 = "DSN=pervasiveDSN;ServerName=SERVER;UID=report;PWD=PW;ArrayBufferSize=8;TransportHint=TCP;ArrayFetchOn=1;AutoDoubleQuote=0;DecimalSymbol=."
  strConnect2 = "DSN=pervasiveDSN;ServerName=SERVER;UID=update;PWD=PW;ArrayBufferSize=8;TransportHint=TCP;ArrayFetchOn=1;AutoDoubleQuote=0;DecimalSymbol=."
  strConnect3 = "DSN=accessDSN;UID=IUSR_USER;PWD=PW;DBQ=\\server\share$\db.mdb;SystemDB=\\server\share$\db.mdw;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"
%>

2)  In my asp page at the top I'll code:

<!--  #include virtual="/include/cs.asp" -->

3)  Further in my asp page I'll make reference the connect string like:

  server.ScriptTimeout = 240
  set adoConn = server.CreateObject("ADODB.CONNECTION")
  adoConn.Open strConnect1
  Set oRS = server.CreateObject("ADODB.Recordset")
  '...

4)  Also, we lock down the include folder and only give the IUSR_<servername> read access to it...

Hope this helps,
Preece
 
0
 
LVL 12

Expert Comment

by:Preece
ID: 16746221
By the way, the include folder should be off the root of the webserver folder:

E:\Inetpub\wwwroot\yourwebservername\include\

Preece
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Expert Comment

by:HappyFunBall
ID: 16746272
True, the include file is another method, but it does require you to add the include statement on every page.  The benefit of using the global.asa page and assigning an Application variable is that you control everything in one place.
0
 
LVL 1

Author Comment

by:Flower11
ID: 16746409
I am trying the Global.asa:

Global.asa
=======

I created a Notepad file named Global.asa located on ftp://111.222.333.44/html/wwwroot/  The file contains:

<script language="vbscript" runat="server">
   Sub Application_OnStart
     Application("Conn") = "Provider=SQLOLEDB; Data Source=mydatasource; Initial Catalog=mycatalog; User ID=myUserID; Password=mypassword"
   End Sub
</script>

The ASP page tries to connect like this:

set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Application("Conn")

What do I forget?  I'll try the include file tomorrow.

0
 
LVL 9

Expert Comment

by:HappyFunBall
ID: 16746457
That looks right to me.  You may need to restart IIS.
0
 
LVL 13

Expert Comment

by:nurbek
ID: 16748977
in order to make global.asa to work

global.asa should be in a root directory,

you may create a virtual directory with a name MYSITE (like folder is C:\mywebsites\mysite)
and put your global.asa into mysite folder


0
 
LVL 7

Expert Comment

by:SimonBlake
ID: 16750181
Note: If your going to use global.asa - you might also need to set it as an application in the IIS manager in order for it to be executed. If it's not an application, IIS won't run it.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question