OLEDB Connection String

M

MasterChief

I have a OLEDB Connection String that is working very well for me. My
question is that I read that you can store the Connection String in a
seperate include file or somewhere else. I am just wondering where is
the proper place to store this Connection String and how do I call it
from my application.
My Example is below

Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.RecordSet")
Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
Catalog = TestSQL; User Id = sa; Password = test"
sSQL = "SELECT * FROM Html ORDER BY HtmlName ASC"
Set Rs = Conn.Execute(sSQL)
Do While NOT Rs.EOF
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing

Would the answer be to put
Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
Catalog = TestSQL; User Id = sa; Password = test"
into an asp page and then use <!--#include file="test.asp"-->
like

Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.RecordSet")
<!--#include file="test.asp"-->
sSQL = "SELECT * FROM Html ORDER BY HtmlName ASC"
Set Rs = Conn.Execute(sSQL)
Do While NOT Rs.EOF
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
 
B

Bob Barrows [MVP]

MasterChief said:
I have a OLEDB Connection String that is working very well for me. My
question is that I read that you can store the Connection String in a
seperate include file or somewhere else. I am just wondering where is
the proper place to store this Connection String and how do I call it
from my application.
My Example is below
Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
Catalog = TestSQL; User Id = sa; Password = test"

I hope you are not really using the sa account for your application code ...
and that the password is not really "test".

Would the answer be to put
Conn.Open "Provider=SQLOLEDB; Data Source = TEST\SQLEXPRESS; Initial
Catalog = TestSQL; User Id = sa; Password = test"
into an asp page and then use <!--#include file="test.asp"-->

That's one way. I ususally create a function in the include file that
returns the connection string:

<%
function GetConnectString()
GetConnectString="<your connection string>"
end function
%>

Then
<!--#include file="test.asp"-->
<%
dim sConnect
sConnect=GetConnectString
....
Conn.Open sConnect
%>

Using a function allows you to add arguments to control which connection
string to return if you have multiple strings that could be used (perhaps a
test vs production environment). You could also use the server_name
servervariable to control which connection string gets returned.

Equally valid is using an application variable to store the string,
initializing it in the application_onstart event in global.asa.

Bob Barrows
 
M

MasterChief

Yes you are correct about the password and such. I just wanted to throw
up an example really fast. Thank you for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,010
Latest member
MerrillEic

Latest Threads

Top