August 4, 2005 at 12:14 pm
I am attempting to setup the connection "application" for connecting to my SQL server using ASPs global.asa, and then referencing that applicaion every time one of my ASP pages needs to open a connection to the SQL server. The problem is that I have compared my code to the code I've found on nearly every forum post I've come across on Google, and though mine is the same, it still doesn't work.
====Global.asa====
<script LANGUAGE="VBScript" RUNAT="Server">
Dim ConnStr
ConnStr = "Driver={SQL Server}; Provider=SQLOLEDB; Network Library=LIBNAME; Data Source=DSNAME; Initial Catalog=CATNAME; User Id=USER; Password=PASSWORD;"
Application("ConnStr") = ConnStr
End Sub
</script>
================================
====Cut from one of my ASPs====
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Application("ConnStr")
================================
I can make my connections properly if I define the connection variables in every ASP page, but I would prefer to keep login info out of the pages and have a single file to change in case I have to move a server or something. Could someone point out my mistake?
August 5, 2005 at 6:15 am
I keep a separate .asp page with that configuration and 'INCLUDE' it at the very top on all pages. Take the code out of global.asa.
<!--#INCLUDE virtual="/virtualFolder/globalconfig.asp"-->
If you're using visual interdev, you can 'set a project reference' to ADO and it will add the <meta> tags to global.asa so your ado constants will work or you can just add them yourself.
Incidently, I never use <script runat=server> in classic asp. <% %> Server tags seem to work best. However, <script runat=server> is used in asp.net.
August 5, 2005 at 7:51 am
I'm not sure if you were just paraphrasing your global.asa above or not...but if you were NOT paraphrasing, you forgot to use Sub Application_OnStart(). I see that you have an "End Sub" but not a beginning to your subroutine. Maybe that's why the application variable is not being set.
August 5, 2005 at 9:08 am
iyoung800: You're correct about the paraphrasing, though it was unintentional . I did have the "Sub Application_OnStart()" before the code I posted. I noticed that this morning when I read my post again. Doh!
In regards to Tim's suggestion, I gave includes a try, and I it took care of my problem. The code wasn't quite as striaght forward as Tim's post lead on, but nothing that a crash course in SSI couldn't fix. I'm sure things would have been a little quicker if I used something to build my pages, since WordPad's debugger doesn't catch much .
Thanks for your help!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply