Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 25th, 2003, 10:56 AM
sqlboy sqlboy is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Memphis
Posts: 10 sqlboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry miserable problem

Hi there,

I have an 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 net, it prompts me error messages. This is not an single case. Every database 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 database. 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 database.The database 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.

In order to sort out the problem, i also specify explcitly all the variable names with INSERT command, i am getting the below mention error on my IIS as well as on the web. The error i am getting is :

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert the value NULL into column 'recnum', table 'recruitment' ; column does not allow nulls. INSERT fails.

/minorities/postrec.asp, line 35

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

For, your convienence i am attaching all the files with this mail.

Thanks for your anticipations.
sqlboy
Attached Files
File Type: txt recruit.txt (7.3 KB, 381 views)

Reply With Quote
  #2  
Old March 26th, 2003, 07:28 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Your insert statement is wrong - it needs to be in the format:

"INSERT INTO tablename (fieldnames,...) VALUES (fieldvalues, ...)"

you are missing the fieldname part..

also, you cannot insert a value into a auto-incrementing field

Reply With Quote
  #3  
Old March 26th, 2003, 08:14 AM
sqlboy sqlboy is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Memphis
Posts: 10 sqlboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hi there,
Thanks for response. But i tried the same thing very early. When i supplied the fields, doing something like this..

Insert into recruitment( fields2, fields3....) values(value2, value3,.... ) . Here the field1 is Identity field(autoincrement)

i am getting this error..

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert the value NULL into column 'recnum', table 'recruitment' ; column does not allow nulls. INSERT fails.

sqlboy

Reply With Quote
  #4  
Old March 26th, 2003, 08:30 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
You might want to double check that your primary key field is in fact an "identity" field. From my experience, you shouldn't be getting a "cannot insert NULL" error if this is the case.

Reply With Quote
  #5  
Old March 26th, 2003, 09:22 AM
sqlboy sqlboy is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Memphis
Posts: 10 sqlboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post

hi there,
Well, the error which i was mentioning in my previous reply occured on both. I mean to say that on mine IIS as well as on web.

BUT, when i am not supplying the fields it's working fine on IIS as i mentioned in my problem. Now comming to your response...

Both tables are same. One works fine on IIS and other's not on web ? How is it feasible ?

Does it mean that SQL2000 not import the files correctly ? Or Is it one of the drawbacks of MSSQL2000 ?

If you say then I'll check the Primary Key of mine remote server tables.

sqlboy

Reply With Quote
  #6  
Old March 26th, 2003, 05:33 PM
numbernine numbernine is offline
Up To His Eyes In Ads
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Chicago
Posts: 160 numbernine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 25 sec
Reputation Power: 7
Importing and Exporting SQL Server tables between databases will often result in blown away primary keys and/or identity properties. Double-check the properties on your identity field and use the syntax that Stumpy recommended. It should work.

Reply With Quote
  #7  
Old March 27th, 2003, 12:57 AM
sqlboy sqlboy is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Memphis
Posts: 10 sqlboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post

Hi there,
Thanx for your reply numbernine. You are right, SQl not import / Export the files correctly. I found that few of tables on the web have no Primary key which they had.

It seems that MSSQL ate that key when they import / export it.

So, i guess that it is the reason of mine problem. May be, i 'll sort out rest of things by myself.

Thanks stumpy too !!!

Thanks alot for your anticipations.
sqlboy

Reply With Quote
  #8  
Old March 27th, 2003, 01:01 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
For transferring tables using DTS - use the "Transfer Objects" method to keep all your tables, keys, etc intact.

Reply With Quote
  #9  
Old March 27th, 2003, 01:51 AM
sqlboy sqlboy is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Memphis
Posts: 10 sqlboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post

Thanks Stumpy,
For your valuable suggestion. But, I always transfered the tables thru DTS import / Export wizard.

sqlboy

Last edited by sqlboy : March 27th, 2003 at 08:25 AM.

Reply With Quote
  #10  
Old March 29th, 2003, 06:49 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Yup, thats' what I'm talking about. After you've selected the source and destination DB's, it asks you what method you'd like to use to transfer the data. Choose the 3rd method, "Transfer Objects" to keep all meta data intact.

Reply With Quote
  #11  
Old April 29th, 2003, 08:52 AM
himanshus16 himanshus16 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: New Delhi, INDIA
Posts: 7 himanshus16 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb The Solution.

Hi SQLBoy,

I have seen such Problems. It definitely comes because, when you try to create Table and other Objects, using DTS, that certain indexes, default values etc. are not copied/Applied. This is the Reason why the same code that is working fine on your IIS, is not working on web. So, You can try out this:

1.) Take the Back Up of your Local Database, by using the "Back Up Database" utility of SQL.

2.) Ftp the file(.BAK) onto the web server.

3.) There create a blank database by the same name as local database.

4.) Restore the Database, using the SQL's "Restore Database Utility".

5.) This will create a Fool Proof database and then, you can manually delete the data from the table if required.

Try this out.....this might help you.

Reply With Quote
  #12  
Old April 29th, 2003, 09:09 AM
sqlboy sqlboy is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Memphis
Posts: 10 sqlboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post

Himanshu,
Above all thanx for the reply. But the much better option was allready provided by the stumpy. Your suggestion is also valuable, no doubt et all.

Sqlboy

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > SQLServer primary key problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT