connection code, I think.

M

middletree

I'm used to doing ASP with SQL Server, but now I'm doing something with
Access. Never understood connection strongs, but managed to get by with
pasted code. Now, I can't make this work. Can anyone see what's wrong?

Background: This page is what shows up after the page with the form in it.
That page uses the Post method and points to this one. Database is called
Shape, the table this time is called Personal. Error I get is pasted at the
end.

---------------------------------------
(include adovbs.inc)

objConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\wwwroot\Grace\Shape.mdb;User Id=admin;Password=;"

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Personal", objConnection, adOpenStatic, adLockPessimistic,
adCmdTable

' *** request variables from the form ***
strFirstName = Replace(Trim(Request.Form("FirstName")),"'","''")
strLastname = Replace(Trim(Request.Form("LastName")),"'","''")

strSQL = "set nocount on; INSERT INTO Personal(FirstName,LastName) VALUES
(strFirstName,strLastName); select @@identity [newid];"
Set rs=objConnection.execute (strSQL)
strPersonalID = RS("newid")
rs.Close
Set rs = Nothing

--------------------------------------

a.. Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'objConnection'
/grace/shapethankyou.asp, line 149

where line 149 is the one which says:

Set rs=objConnection.execute (strSQL)
 
D

dlbjr

strFirstName = Replace(Trim(Request.Form("FirstName")),"'","''") strLastname
= Replace(Trim(Request.Form("LastName")),"'","''") strSQL = "set nocount on;
INSERT INTO Personal(FirstName,LastName) VALUES(strFirstName,strLastName);
select @@identity [newid];" Set ObjConn = CreateObject("ADODB.Connection")
objConn.Open =
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\Inetpub\wwwroot\Grace\Shape.
mdb;User Id=admin;Password=;" Set ObjCmd = CreateObject("ADODB.Command") Set
rs = Server.CreateObject("ADODB.Recordset") rs = ObjCmd.execute (strSQL)
strPersonalID = rs("newid") rs.Close Set rs = Nothing Set ObjCmd = Nothing
Set ObjConn = Nothing

-dlbjr

invariable unerring alien
 
K

Ken Schaefer

a)

Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Inetpub\wwwroot\Grace\Shape.mdb;User
Id=admin;Password=;"

objRS.Open ...

b) You can't do batched statements in Access, so remove the "SET NOCOUNT ON"
bit from the beginning of your SQL statement (actually, SET NOCOUNT ON
doesn't do anything in Access anyway)

Cheers
Ken



: I'm used to doing ASP with SQL Server, but now I'm doing something with
: Access. Never understood connection strongs, but managed to get by with
: pasted code. Now, I can't make this work. Can anyone see what's wrong?
:
: Background: This page is what shows up after the page with the form in it.
: That page uses the Post method and points to this one. Database is called
: Shape, the table this time is called Personal. Error I get is pasted at
the
: end.
:
: ---------------------------------------
: (include adovbs.inc)
:
: objConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data
: Source=C:\Inetpub\wwwroot\Grace\Shape.mdb;User Id=admin;Password=;"
:
: Set rs = Server.CreateObject("ADODB.Recordset")
: rs.Open "Personal", objConnection, adOpenStatic, adLockPessimistic,
: adCmdTable
:
: ' *** request variables from the form ***
: strFirstName = Replace(Trim(Request.Form("FirstName")),"'","''")
: strLastname = Replace(Trim(Request.Form("LastName")),"'","''")
:
: strSQL = "set nocount on; INSERT INTO Personal(FirstName,LastName) VALUES
: (strFirstName,strLastName); select @@identity [newid];"
: Set rs=objConnection.execute (strSQL)
: strPersonalID = RS("newid")
: rs.Close
: Set rs = Nothing
:
: --------------------------------------
:
: a.. Error Type:
: Microsoft VBScript runtime (0x800A01A8)
: Object required: 'objConnection'
: /grace/shapethankyou.asp, line 149
:
: where line 149 is the one which says:
:
: Set rs=objConnection.execute (strSQL)
:
:
:
:
:
:
:
 
M

middletree

OK, I'll try that. I find this stuff really confusing.

As for item #2, I copied that from a site I have been working on using SQL
Server. Thanks for clearing me up.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top