Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 4th, 2004, 08:35 PM
TaoEntropy TaoEntropy is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 10 TaoEntropy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Upsizing Access to SQL - Can't add new records

Hello,

I have some asp pages that used to update an access database.

I have uploaded the access database to sql server and changed lots of things in my code and databases including the connection string, date delimiters (# to '), database fields that sql doesn't like, and created new sql primary keys that auto increment.

It seemed like i had most everything ironed out, when I realized that the sql server would allow me to update and query records, but not to add brand new records.

What might be the problem?

I've damaged several pieces of furniture and I'm afraid my head might be next!

Thanks!

Reply With Quote
  #2  
Old March 4th, 2004, 10:58 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
How are you trying to add records?

Reply With Quote
  #3  
Old March 5th, 2004, 12:38 AM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
Check over the upsized table definitions. One thing that sometimes gets lost in upsizing is primary key information. Missing primary keys can make recordsets be non-updateable.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #4  
Old March 8th, 2004, 06:44 PM
TaoEntropy TaoEntropy is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 10 TaoEntropy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks!

Reply With Quote
  #5  
Old March 9th, 2004, 02:22 PM
TaoEntropy TaoEntropy is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 10 TaoEntropy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
OK, I think I’ve figured some things out and can describe my problem better.



Like I said before, I moved from an access database to a sql server database.



What seems to be happening is that when I used the access database I could write values to the database and then attach them to local session variables in one step.



For some reason SQL server does not want to allow me to write a new record to the database, retrieve the automatically generated UserID, and attach it to the session variables in one step.



I can kinda make the page work by adding the new record in one step and then going back to the database and filtering the record set again, thus retrieving the new record with the new User ID value.



The problem with that is that I don’t have any real unique value to filter except the auto-generated user ID by the SQL database.



Why is it that access will allow me to use its new autogenerated UserID and SQL won’t? Is there some kinda of setting I’ve got wrong. I really hope so, because I think making a second trip to the SQL database is the wrong way to go.



If there is no way to do this, is there anyway to filter my second record set by the last User ID entered in the database before it reaches EOF? Even so, that won’t really guarantee that the database is pulling the same record, if by some chance someone else is entering a record at the same time.



Here’s my code:







<!--#include file="connection.asp"-->

<%

Dim rsUsers

Set rsUsers = Server.CreateObject("ADODB.Recordset")

rsUsers.Open "Users", objConn, adOpenForwardOnly, adLockOptimistic, adCmdTable



If Session("userID") <> "" Then ' currently logged-on user

rsUsers.Filter = "UserID = '" & Session("userID") & "'"

Else ' New session

rsUsers.Filter = "EMailAddress = '" & Request.Form("email") & "'" & _

"AND Password = '" & Request.Form("password") & "'"

If rsUsers.EOF Then ' User not found

rsUsers.AddNew ' ...so add a new record

' Else

' Email address and password matched with DB records -

' In this case we'll allow this to update user's useral details

End If

End If

' write useral details to record

rsUsers("EMailAddress") = Request.Form("email")

rsUsers("Password") = Request.Form("password")

rsUsers("FName") = Request.Form("FName")

rsUsers("LName") = Request.Form("LName")

rsUsers("Fax") = Request.Form("Fax")

rsUsers("Organization") = Request.Form("Organization")

rsUsers("Phone") = Request.Form("Phone")

rsUsers("StreetAddress1") = Request.Form("Address1")

rsUsers("StreetAddress2") = Request.Form("Address2")

rsUsers("City") = Request.Form("City")

rsUsers("State") = Request.Form("State")

rsUsers("PostalCode") = Request.Form("PostalCode")

rsUsers("Country") = Request.Form("Country")

rsUsers("Active") = True

rsUsers("LastLogin") = Now

rsUsers.Update ' update the database





rsUsers.Filter = "EMailAddress = '" & Request.Form("email") & "'" & _ ' pull out the updated record again

"AND Password = '" & Request.Form("password") & "'"









Dim strName, strValue ' create session variables

For each strField in rsUsers.Fields

strName = strField.Name

strValue = strField.value

Session(strName) = strValue

Next

Session("blnValidUser") = True







Session("UserID") = rsUsers("UserID")



' declare that current user is validated



Response.Redirect "MenuForRegisteredUsers.asp"



%>

Thanks for your help! I hope we can figure this one out!

Reply With Quote
  #6  
Old March 9th, 2004, 04:32 PM
TaoEntropy TaoEntropy is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 10 TaoEntropy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Okay. Someone way able to help me and provide the solution. It was the way I opened my record set. I should have used adOpenKeyset instead of adForwardOnly.


Thanks to Imar Spaanjaars on the www.wrox.com Beginning ASP 3.0 book forum!

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Upsizing Access to SQL - Can't add new records


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 3 hosted by Hostway
Stay green...Green IT