ASP Database Connection help

Anime_Fan

[H]ard|Gawd
Joined
Mar 1, 2004
Messages
1,207
I am currently having some trouble getting connected to a MS Access Database using SQL.

If I place the database in the same folder as my ASP files the connection works using the following code:

'Create DB Connection
DIM objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("CSC_Support.mdb") & ";"
objConn.Open

But I would like it to connect to the database over the network.

I have tried this and it doesn't work:

DIM objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("//dcfile02/tdrive$/cadd/Support/Database/CSC_Support.mdb") & ";"
objConn.Open

I have tried placing it directly after the Data Source as well and it doesnt connect.

I am rather new to ASP is there something I am missing?
 
What are the forward slashes for? Don't you mean backslashes?
 
I've tried both ways. Some examples I have viewed used the forward slashes however.
 
Then we'll have to dig into it: What does "doesn't work" mean? What error do you get, specifically? What does Server.MapPath() end up returning? What account is running in this context? Does it have rights to that share, directory, and file?
 
Well I don't actually get an error it just gives me a page can't be displayed message. The system account is what it is running under to my knowledge and it should have full access as no security has been set up on the folder yet.
 
I still cant seem to connect over the network to the database. Anybody have a different method of doing this?

Here is more of the script. Does anybody see a problem with any of this?

'
'*******************************************************
' Save info to Database
'*******************************************************
'
'Declare Variables
DIM strfirstName, strlastname, strEmail, strPhoneNum, strLocation, strService, strPriority, strMessage, strDate
strfirstName = Request.Form("firstName")
strlastname = Request.Form("lastname")
strEmail = Request.Form("email0")
strPhoneNum = Request.Form("tel0")
strLocation = Request.Form("location")
strService = Request.Form("service")
strPriority = Request.Form("CAD_Priority")
strMessage = Request.Form("enquiry")

'Adds a 0 to the month if it is a single digit month

strDay = Day(Date)
strMonth = Month(Date)
if strMonth < 10 then
strMonth = "0" & Month(Date)
end if
strYear = Year(Date)
strDate = strMonth & "/" & strDay & "/" & strYear

' Create DB Connection
DIM objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath ("\\dcfile02\tdrive$\cadd\Support\Database\CSC_Support.mdb") & ";"
objConn.Open

SQLStmt = "INSERT INTO Service_Request (First_Name,Last_Name,Email,Phone_Number,Location,Service,Priority,Message,Submit_Date)"
SQLStmt = SQLStmt & "VALUES (" & "'" & strfirstName & "'"
SQLStmt = SQLStmt & ",'" & strlastName & "'"
SQLStmt = SQLStmt & ",'" & strEmail & "'"
SQLStmt = SQLStmt & ",'" & strPhoneNum & "'"
SQLStmt = SQLStmt & ",'" & strLocation & "'"
SQLStmt = SQLStmt & ",'" & strService & "'"
SQLStmt = SQLStmt & ",'" & strPriority & "'"
SQLStmt = SQLStmt & ",'" & strMessage & "'"
SQLStmt = SQLStmt & ",'" & strDate & "'" & ")"

' Execute Statement
objConn.Execute(SQLStmt)
 
make sure users have write privilages to the .mdb file. check the file itself, not just the folder it's in.
 
I'm surprised it's running under the system account; why wouldn't you be using the IUSR_MACHINENAME account? Did you set IIS to run under the machine account, and disable its security?

If you turn on auditing for the machine hosting the files, what do you see in the security event log?

Can you write a script that will open a text file and read it from that same machine/share/directory?

Why don't you turn on error messages for ASP so you get some diagnostics instead of just failing to load the page?

What's your W3SVC log say about the error?

There shouldn't be a space between "Pr" and "iority", or between "Ph" and "one_Number".

With this code, you're wide open to SQL substitution attacks, and your server is ready to be slaughtered. Please use bindings for your parameters instead!
 
I am not sure how those spaces got in there. They aren't in my ASP file. It must have been a copy paste issue. Remember that this code works as long as the database is in the same folder as these files.

Also I am an intern, there is no way in hell they are going to let me have access to any of that stuff. The IT department here is a little on the harsh side.

As for the account it runs under I have no idea. I just assumed it runs under the server system account. I can ask nobody for help here because nobody seems to know anything about ASP even though they want me to code in ASP, it is pretty freaking funny to me.

Believe me though its not a security issue, the folder has everyone permission. I feel that its just not connecting out over the network because my connection string probably isn't correct. I can't seem to find any other examples though to help me.
 
Ok guys LOL so yeah I missed a folder permission in the path and it was partially a security issue. But I also had to change my connection string to look like this:

' Create DB Connection
DIM objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=//dcfile02/tdrive$/cadd/Support/Database/CSC_Support.mdb"
objConn.Open
 
Looks like you're going to learn a lot about debugging. That's the path I was trying to lead you down when I asked "What does Server.MapPath() end up returning?", but you didn't want to check.

I'm glad you got it workin in the end. Good luck with your project!
 
Back
Top