Solved

Error 0x8004e10 when inserting records with the execute method

Posted on 2006-11-20
9
338 Views
Last Modified: 2012-06-22
At a certain point my program goes like this:
---------------------------------------------------

inputDataLimIniPublic      = dateadd("yyyy",2,now())

sql="insert into tblN2PecasVDAnuncios(IDCompra, DataLimIniPublic, Destacado, ComFoto) values("

sql=sql & inputIDCompra
sql=sql & ", #" & inputDataLimIniPublic  & "#"
sql=sql & ", "  & inputDestacados
sql=sql & ", "  & inputComFoto

sql=sql & ")"

for anuncio=1 to inputNumAnuncios
%>
<!--#include file="ConexaoBDClientes_Exec.inc"-->
<%
oConn.close
set oConn      = Nothing
next
%>

The include file is as follows:
---------------------------------

<%
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN=Clientes"
set rs = Server.CreateObject("ADODB.RecordSet")
oConn.execute sql,,129
%>

Now some facts:

0 - The browser shows:

Microsoft OLE DB Provider for ODBC Drivers (0x8004e10)
[Microsoft][Microsoft Access ODBC Driver] Few parameters, expected 1.
ConexaoBDClientes_Exec.inc, line 4

1 - This code runs perfectly in my desktop PC running W2K (English Version);
2 - The same code raises the error in my Laptop running XP (Portuguese Version);
3 - PC had Access 2000, Laptop has Access 2003;
4 - I did not convert the database;
5 - Field IDCompra is autonumber;
6 - Field inputDataLimIniPublic is date;
7 - Remaining fields are logical;

Any clues? I would also appreciate a suggestion about a good ADODB reference on the web. Thanks
0
Comment
Question by:gustavoneves
  • 5
  • 4
9 Comments
 
LVL 22

Expert Comment

by:WMIF
ID: 17981526
>>5 - Field IDCompra is autonumber;

if the field is auto number, then you shouldnt include it in an insert statement.  it should be skipped to let the db fill it in.
0
 

Author Comment

by:gustavoneves
ID: 17983174
I'm sorry WMIF, but fact #5 is wrong, it should read:

5 - Field IDCompra is number;

There also should be a fact #8:

8 - The table has an autonumber field as its primary key;
0
 
LVL 22

Expert Comment

by:WMIF
ID: 17983592
ah.  why are you using an include file for only 4 lines?  your include is creating a recordset and you arent even using it.  what i would suggest is to put the connection string into an include file so you can change that if you need to.  then put that code into your page itself.  you are opening a connection and closing it for each time through the loop.  

the include file should be simple, like this:
<%
connstring = "DSN=Clientes"
%>

put the include file at the top of the page and open the connection like this:
oConn.open connstring

then your loop will look something like this:
<!--#include file="ConexaoBDClientes_Exec.inc"-->
<%
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connstring
for anuncio=1 to inputNumAnuncios
  oConn.execute sql
next
oConn.close
set oConn     = Nothing



also, what are you trying to do with the 129 on the execute line?  i cant find that option on this page:
http://www.w3schools.com/ado/met_comm_execute.asp
0
 

Author Comment

by:gustavoneves
ID: 17986249
First, the reason why my include file is so short:

- My website is hosted by brinkster, and my hosting plan only allows DSN-less connections;
- Over the years, I've been developing my website using local DSN connections;
- I have 2 different include files with the same name, one for development and other for the on-line site, that goes like this:

<%
Set oConn=Server.CreateObject("ADODB.Connection")
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
sMapPath = Server.MapPath("\")
sMapPath = Mid(sMapPath, 1, InStrRev(sMapPath,"\")-1) & "\database\Website.mdb;" & "Persist Security Info=False;"
sConnString = sConnString & sMapPath
oConn.Open(sConnString)
oConn.Execute sql,,129
%>

- With this (pre-historic?) technique I can write my programs in a way they will work in both platforms;

(I wonder if I could use DSNLess connections localy, could it be done? If so, the includes would simply disappear).

Second, why the 129? Please check http://www.aspfaq.com/show.asp?id=2191 for this chunk of code:

<%
    sql = "INSERT INTO <table> (fields) VALUES (values)"
    set conn = CreateObject("ADODB.Connection")
    conn.open "<connection string>"
    conn.execute sql, , 129
    ' 129 is the constant for adExecuteNoRecords + adCmdText
    ...
%>


0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 22

Expert Comment

by:WMIF
ID: 17989829
>>' 129 is the constant for adExecuteNoRecords + adCmdText

gotcha.  i think i would like to try that line without the options at all.
conn.execute sql ', , 129



>>First, the reason why my include file is so short:

you can leave everything how you have it, you just need to change the connection string.  i do the same thing you do, except i use only one include file with both strings.  on the dev server i comment out the live string.  on the live server, i comment out the dev string.

<%
' comment string not in use.
'connstring = "DSN=Clientes"  ' development string
connstring = "brinkster_dsnless_string"  ' production string
%>




>>I wonder if I could use DSNLess connections localy, could it be done?

this can be done also, but i wouldnt completely remove the include file.  do it as i suggested above and it will work very smoothly.  check out this site for example query strings.
www.connectionstrings.com
0
 

Author Comment

by:gustavoneves
ID: 18006996
I finally managed to find what was causing the error: the error was due to the 2 boolean fields. Please look at the way I had to build the sql statement - only this way I could make it work - is there a more adequate way to do this?
Btw, I followed your suggestions about the use of ADO, and it works fine, with or whithout
the 129 parameter.

<%

inputNumAnuncios      =      5
inputIDCompra      =      214
inputDataLimIniPublic      =      dateadd("yyyy",2,now())

inputDestacados      =      False
inputComFoto      =      True

sql="insert into tblN2PecasVDAnuncios(IDCompra,DataLimIniPublic,Destacado,ComFoto) values("

sql=sql         & inputIDCompra
sql=sql & ", #" & inputDataLimIniPublic  & "#"

// Can you believe this?

if inputDestacados = True then
      sql = sql & ", True"
else
      sql = sql & ", False"
end if

if inputComFoto = True then
      sql = sql & ", True"
else
      sql = sql & ", False"
end if

sql=sql & ")"

response.write(sql & "<br><br>")

%>
<!--#include file="ConBDClientes.inc"-->
<%

set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open ConnString

for anuncio=1 to inputNumAnuncios
     oConn.execute sql
next

oConn.close
set oConn      =      Nothing
%>

0
 
LVL 22

Expert Comment

by:WMIF
ID: 18009702
where are the inputDestacados and inputComFoto values coming from?
0
 

Author Comment

by:gustavoneves
ID: 18043908
The contents of these 2 variables come from 2 boolean fields of a table in the same DB. Please remember that this DB was created under the Portuguese version of Access 2000, although, in theory, this should not be a problem.
0
 
LVL 22

Accepted Solution

by:
WMIF earned 350 total points
ID: 18046909
how were trying to get those values into the string before?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now