connection code, I think.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • middletree

    connection code, I think.

    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=Micro soft.Jet.OLEDB. 4.0;Data
    Source=C:\Inetp ub\wwwroot\Grac e\Shape.mdb;Use r Id=admin;Passwo rd=;"

    Set rs = Server.CreateOb ject("ADODB.Rec ordset")
    rs.Open "Personal", objConnection, adOpenStatic, adLockPessimist ic,
    adCmdTable

    ' *** request variables from the form ***
    strFirstName = Replace(Trim(Re quest.Form("Fir stName")),"'"," ''")
    strLastname = Replace(Trim(Re quest.Form("Las tName")),"'","' '")

    strSQL = "set nocount on; INSERT INTO Personal(FirstN ame,LastName) VALUES
    (strFirstName,s trLastName); select @@identity [newid];"
    Set rs=objConnectio n.execute (strSQL)
    strPersonalID = RS("newid")
    rs.Close
    Set rs = Nothing

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

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

    where line 149 is the one which says:

    Set rs=objConnectio n.execute (strSQL)







  • dlbjr

    #2
    Re: connection code, I think.

    strFirstName = Replace(Trim(Re quest.Form("Fir stName")),"'"," ''") strLastname
    = Replace(Trim(Re quest.Form("Las tName")),"'","' '") strSQL = "set nocount on;
    INSERT INTO Personal(FirstN ame,LastName) VALUES(strFirst Name,strLastNam e);
    select @@identity [newid];" Set ObjConn = CreateObject("A DODB.Connection ")
    objConn.Open =
    "Provider=Micro soft.Jet.OLEDB. 4.0;DataSource= C:\Inetpub\wwwr oot\Grace\Shape .
    mdb;User Id=admin;Passwo rd=;" Set ObjCmd = CreateObject("A DODB.Command") Set
    rs = Server.CreateOb ject("ADODB.Rec ordset") rs = ObjCmd.execute (strSQL)
    strPersonalID = rs("newid") rs.Close Set rs = Nothing Set ObjCmd = Nothing
    Set ObjConn = Nothing

    -dlbjr

    invariable unerring alien


    Comment

    • Ken Schaefer

      #3
      Re: connection code, I think.

      a)

      Set objConnection = Server.CreateOb ject("ADODB.Con nection")
      objConnection.O pen _
      "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
      "Data Source=C:\Inetp ub\wwwroot\Grac e\Shape.mdb;Use r
      Id=admin;Passwo rd=;"

      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



      "middletree " <middletree@hto mail.com> wrote in message
      news:eQquO1PcDH A.356@TK2MSFTNG P11.phx.gbl...
      : 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=Micro soft.Jet.OLEDB. 4.0;Data
      : Source=C:\Inetp ub\wwwroot\Grac e\Shape.mdb;Use r Id=admin;Passwo rd=;"
      :
      : Set rs = Server.CreateOb ject("ADODB.Rec ordset")
      : rs.Open "Personal", objConnection, adOpenStatic, adLockPessimist ic,
      : adCmdTable
      :
      : ' *** request variables from the form ***
      : strFirstName = Replace(Trim(Re quest.Form("Fir stName")),"'"," ''")
      : strLastname = Replace(Trim(Re quest.Form("Las tName")),"'","' '")
      :
      : strSQL = "set nocount on; INSERT INTO Personal(FirstN ame,LastName) VALUES
      : (strFirstName,s trLastName); select @@identity [newid];"
      : Set rs=objConnectio n.execute (strSQL)
      : strPersonalID = RS("newid")
      : rs.Close
      : Set rs = Nothing
      :
      : --------------------------------------
      :
      : a.. Error Type:
      : Microsoft VBScript runtime (0x800A01A8)
      : Object required: 'objConnection'
      : /grace/shapethankyou.a sp, line 149
      :
      : where line 149 is the one which says:
      :
      : Set rs=objConnectio n.execute (strSQL)
      :
      :
      :
      :
      :
      :
      :


      Comment

      • middletree

        #4
        Re: connection code, I think.

        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.

        "Ken Schaefer" <kenREMOVE@THIS adOpenStatic.co m> wrote in message
        news:uYgRvGScDH A.3016@tk2msftn gp13.phx.gbl...[color=blue]
        > a)
        >
        > Set objConnection = Server.CreateOb ject("ADODB.Con nection")
        > objConnection.O pen _
        > "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
        > "Data Source=C:\Inetp ub\wwwroot\Grac e\Shape.mdb;Use r
        > Id=admin;Passwo rd=;"
        >
        > objRS.Open ...
        >
        > b) You can't do batched statements in Access, so remove the "SET NOCOUNT[/color]
        ON"[color=blue]
        > bit from the beginning of your SQL statement (actually, SET NOCOUNT ON
        > doesn't do anything in Access anyway)
        >
        > Cheers
        > Ken
        >
        >
        >
        > "middletree " <middletree@hto mail.com> wrote in message
        > news:eQquO1PcDH A.356@TK2MSFTNG P11.phx.gbl...
        > : 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[/color]
        it.[color=blue]
        > : That page uses the Post method and points to this one. Database is[/color]
        called[color=blue]
        > : Shape, the table this time is called Personal. Error I get is pasted at
        > the
        > : end.
        > :
        > : ---------------------------------------
        > : (include adovbs.inc)
        > :
        > : objConnection = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
        > : Source=C:\Inetp ub\wwwroot\Grac e\Shape.mdb;Use r Id=admin;Passwo rd=;"
        > :
        > : Set rs = Server.CreateOb ject("ADODB.Rec ordset")
        > : rs.Open "Personal", objConnection, adOpenStatic, adLockPessimist ic,
        > : adCmdTable
        > :
        > : ' *** request variables from the form ***
        > : strFirstName = Replace(Trim(Re quest.Form("Fir stName")),"'"," ''")
        > : strLastname = Replace(Trim(Re quest.Form("Las tName")),"'","' '")
        > :
        > : strSQL = "set nocount on; INSERT INTO Personal(FirstN ame,LastName)[/color]
        VALUES[color=blue]
        > : (strFirstName,s trLastName); select @@identity [newid];"
        > : Set rs=objConnectio n.execute (strSQL)
        > : strPersonalID = RS("newid")
        > : rs.Close
        > : Set rs = Nothing
        > :
        > : --------------------------------------
        > :
        > : a.. Error Type:
        > : Microsoft VBScript runtime (0x800A01A8)
        > : Object required: 'objConnection'
        > : /grace/shapethankyou.a sp, line 149
        > :
        > : where line 149 is the one which says:
        > :
        > : Set rs=objConnectio n.execute (strSQL)
        > :
        > :
        > :
        > :
        > :
        > :
        > :
        >
        >[/color]


        Comment

        Working...