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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field or code error? Help, please!

Status
Not open for further replies.

EvertonFC

Technical User
Nov 24, 2004
107
GB
Hello

I am writing to ask for assistance with the following error message I am getting:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] Field 'IPAddresses.IPAddress' cannot be a zero-length string.

/main.asp, line 23

This is the code I have:

<%
' Declaring variables
Dim VisitorID, IPAddress, data_source, con, sql_insert

data_source = "driver={Microsoft Access Driver (*.mdb)};DBQ=D:\business\etc.mdb;"

sql_insert = "insert into IPAddresses (VisitorID, IPAddress) values ('" & _
VisitorID & "', '" & IPAddress & "')"


Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insert

' Done. Close the connection
con.Close
Set con = Nothing

%>

and line 23 (reading from the very top of the page) seems to refer to: con.Open data_source (though I may be mistaken).

If the error does not lie in the above code, is it possible that the data type I have in my MS Access fields is wrong?

Much appreciated.

EvertonFC
 
Are you sure that the script variables VisitorID and IPAddress are populated when you build the sql_insert string ?
For debugging purpose you may add the following code before the con.Execute line:
Response.Write sql_insert

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hello PHV

No, nothing appears in either of the VisitorID or IPAddress columns in MS Access.

I suspect what the proble might be is that I am tryting to gather the IP Address of the machine browsing the Web site, with a view to storing it in the IPAddress field.

I thought that the other field, VisitorID, would be populated automatically, as in:

VisitorID IP Address

1 123.123.123.123
2 123.123.123.123
3 123.123.123.123

Do you think I should just get rid of the VisitorID column? I suppose I just wanted a way of identifying IP Addresses with certain visitor IDs.

Many thanks.

EvertonFC
 
From the code you provided, both VisitorID and IPAddress will always be zero-length strings. I don't see anywhere where you assign a value to them. And apparently in the design for the table IPAddresses, the IPAddress field does not allow zero-length strings.

You have two choices:

1. Give the variable IPAddress a value before you execute the SQL statement.

2. Change the design of the IPAddresses table so that the IPAddress field allows zero-length strings (although what would be the point, as you would always be logging nothing but zero-length strings).

Probably what you really want is to retrieve the IP address of the user (ask that in the ASP forums - I don't know) and then assign it to the IPAddress variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top