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

wee problem with Insert satement

Status
Not open for further replies.

sqlkid2k

Technical User
Mar 25, 2003
21
IN
Hi there,

I have a wee problem with the INSERT statement. The problem is very unusual. I would like yours help in the same. The problem is, files are running very well on my IIS but when i posted the same on web, it prompts me error messages. This is not an single case. Every table that has autoincrement fileds(Identity field) will show same error but works fine on my IIS .The error which it prompt is...

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]Insert Error: Column name
or number of supplied values does not match table definition.

/minorities/postrec.asp, line 34

In brief, i would like to put some lights on the code and table. It's a very simple program in which user fill up their events details in the form and the vaules of that form is going to store in the table.The table contain one "AUTO-INCREMENT" (Identity) field which is increment by 1 every times a new records is added. I am using SQL 2000 and ASP.

The snapshot of Insert statement is :

strsql="insert into recruitment values('"& Request("title") & "','"&
Request("cname") & "' , '" _

& request("cdesc") &"' , '"& request("country") &"','"& request("state")
&"' , '"& request("ind") &"' , '" _

& request("indother") &"' , '"& request("level") &"','"& request
("jobdesig") &"' , '"& request("jobfun") &"', '" _

& request("jobdesc") &"' , '"& request("currency") &"','"& request
("lsalary") &"' , '"& request("hsalary") &"', '" _

& request("chkperks") &"' , '"& request("rdohousing") &"','"& request
("numvac") &"' , '"& request("degree") &"', '" _

& request("workexp") &"','"& request("add_info") &"','"& request("email")
&"', '"& request("sms") &"', '" _

& request("address1") &"', '"& request("address2") &"', '"& request
("pincode") &"','"& request("contry") &"', '" _

& request("constate") &"' , '"& request("city") &"','"& request("teloff")
&"','"& request("telhome") &"','"& request("postaddress") &"')"

set recordset = connection.execute(strsql)

I am very well aware what the error message means. But, both tables and files are same. One run fines on my IIS but other show the above mentions error.

What am I doing wrong? I suspect that it might be related to the Identity fields. Or it might be that I just plain can't do this?

Thanks for your anticipations
sqlkid2k
 
Try putting a response.write strsql in your asp page and testing the string it outputs directly on your db

Transcend
[gorgeous]
 
Hi there,
I tried the same also very early. I even tried all the best possible ways to sort out that nasty problem. For instance, i allready did these things......

Insert into values( value2, value3................) , i got
the error. (value1 is identity) OR

Insert into( fields 2, fields3,.)values(values2,values3) i also got the eror. Or at last

Insert into( fields 1(identity field) ,fields2,...........) values ( "" ,values 2, values3,........ ) again got the error.

I was aware that the last statment is totally wrong. But it was a wild guess to sort out the same thing.

sqlkid2k
 
You cannot insert a value into an auto-increment/identity field - the database engine takes care of that. That field should not feature at all in the Insert Statement.

Ken
 
Hi ken,
I know the same. So, what is the bottom line for me ? how can i tackle out that nasty problem ?


sqlkid
 
Question. Are the asp page and your development machine calling the same backend database? IF not maybe the field was set for identity in one but not in the other, but it was still required and wanted a value?

Another thing to try is to move all the processing to SQL Server and do this is a stored procedure. Then call the Stored procedure in the ASP code. This is a faster way to process in general, so you might consider it.
 
Hi there,

Sqlsister, Answer to your first Question is Yes. Both tables and files are exactly same. I also have an sqlclient on the same system where IIS is. After checking the thing i export the tables and data through SQL 2000 Enterprise Manager and Import / Export options. So, there is Question of missing anything in tables.

As far as the second part is concerned, then to be very honest, i am not getting the things clearly. Does you mean to say that, first i make the stored Procedure and then call the stored procedure in ASP ? Or something else.

Thanks for response
sqlkid
 
At the end of the day there are two simple questions:

1 Is your ASP code generating valid SQL that does the job
2 Is that code getting through correctly to the database engine

As Transcend said above, collect the SQL string by writing it out to a page. Paste it into a tool like Query Analyzer and execute it directly against the database.

If the SQL executes without problem in Query Analyzer then look at SQLSister's suggestion that you might be executing against the wrong table/database. You then need to check your database connection string (which may be buried in an INCLUDE file).

Problem at present is we cannot see where in the chain the logic is broken.

Ken
 
yes sqlkid2k, that is exactly was I was suggesting. but cheerio has a good suggestion about getting the exact string the asp page is creating and then pasting it into query analyzer to see what happens. You could also paste it here and we might see the problem too. Another thing to consider is permissions, although this isn't the error I would expect to get if it were a permissions problem. But often when there is a problem where something works fine on development but not when it goes to production or testing it's because the developers have full rights and the web user does not.
 
Hi there,
Thanks to all for your suggestions.

Ken, mine answer is Yes, for both of your Questions. As i said earlier to Transcend, that i did it the thing very earlier. It's running fine. Also, i am not excuting the code against the wrong table. My database connection is fine.I checked it 3rice.

Ken,I am glad that you open a very intresting Question in my mind, which wasn't striking at that time. The Question is :
Does MSSQL ate Primary/Identity key when we export/import tables ?

I was asking b'coz, if it not then i was definetly getting error when i tried to insert the values directly.. LIke..

Insert into tbl (field1,field2,....) values(value1,value2.....)

But that wasn't the case. I guess that problem is here..

SQlSiter, I am still getting the same error after making the Procedure and calling back to my ASP code.

Thanks
sqlkid
 
SQL will not necessarilty move all the constraints, indexes etc. What method was used to move the tables to production?I have never had it not move an identity field except as an identity. IF you take a tool like SQLCompare, it will check specifically the differences between your production and development servers and you can see if there is a problem with this and other tables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top