Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB Connection String Issue

Status
Not open for further replies.

OrWolf

MIS
Mar 19, 2001
291
I'm currently developing several web solutions for a client on a development server. The issue is that the database connection string is different on the production server than the development server. This is a real problem since I have to update all of the connection strings anytime I publish my web. Is there a way I can have my code verify it's location to decide which string to use in my code? Is there another solution? Note: The system default points me to the wrong location, so the location must be specified.

Development:
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/inetpub/intradev/awareness/fpdb/EDF2K.mdb;Persist Security Info=False"

Production:
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/inetpub/ Security Info=False"
 
Just in case anyone's curious in the future, I solved this on my own using the following:

Dim objFSO
Set objFSO = Server.CreateObject _ ("Scripting.FileSystemObject")
If objFSO.FolderExists(Server.MapPath_("..\..\..\intradev")) Then
objConnection.Open [development path here]
ElseIf objFSO.FolderExists(Server.MapPath_("..\..\..\ Then
objConnection.Open [production path here]
End If
Set bojFSO = Nothing
 
You could do it that way or just always use
Server.MapPath("EDF2K.mdb") to find the file path. You don't really need to check if the folders exist. MapPath will return the complete path. Harold Blackorby
hblackorby@scoreinteractive.com
St. Louis, MO
 
When I use that connection method, I get the following error:

Number: 3709

Description: The application requested an operation on an object with a reference to a closed or invalid Connection object.

Is something wrong with my syntax?

Dim objFSO
objFSO = Server.MapPath("RA_DATA_CONN.mdb")
Set objConnection = Server.CreateObject("ADODB.Connection")
Set objRecordset = Server.CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data_ Source=" & objFSO & ";Persist Security Info=False"
 
you would need to Server.MapPath to the actual file, in this case EDF2K.mdb.

good luck -
leo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top