Definite difference between using OLEDB and ODBC as the driver

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Definite difference between using OLEDB and ODBC as the driver

    Hi All

    Some of you may not remember (or even care for that matter ;0)), but I
    mentioned in a previous post that I had difficulty using the OLEDB for
    Access connection over the ODBC one because there were gremlins lurking to
    cock-up my code.

    Well I've managed to source 2 of these problems and would appreciate it if
    you could confirm why they are doing the following and more importantly how
    to correct them:

    set oCmd=Server.CreateObject("ADODB.Command")
    set oCmd.ActiveConnection = oConn
    oCmd.CommandText = "Admin_GetProdList()"
    oCmd.CommandType = 4
    set oRSv=Server.CreateObject("ADODB.recordset")
    oRSv.CursorLocation = 3
    oRSv.open oCmd

    If I leave in the brackets () after Admin_GetProdList, OLEDB reports an
    error, but ODBC works fine. If I remove the brackets OLEDB works and ODBC
    still works. Not a calamity this one, but why is it doing this?

    Set oCmd=Server.CreateObject("ADODB.Command")
    Set oCmd.ActiveConnection = oConn
    oCmd.CommandText = "Admin_GetSpecificProduct('" & strProdID & "')"
    oCmd.CommandType = 4
    'Response.Write oCmd.CommandText
    Set oRSv=Server.CreateObject("ADODB.recordset")
    oRSv.open oCmd

    This one is more important as I can't use my stored procs with OLEDB.

    At present, the above generates the below error on OLEDB, but is fine on
    ODBC:

    Error Type:
    Microsoft JET Database Engine (0x80040E14)
    Syntax error in parameters clause. Make sure the parameter exists and
    that you typed its value correctly.
    /asp/details.asp, line 698

    I thought that the ADO coding was exactly the same irrespective of the
    connection method, but the above appears to be of the contrary?

    Rgds

    Laphan


    Laphan Guest

  2. Similar Questions and Discussions

    1. ODBC driver does not show up in driver list in ODBC data source administrator
      Installed an ODBC driver on a Windows Server 2003 machine. A key shows up in the registry under HKEY_LOCAL_MACHINE- seperate listing under...
    2. (0x80004005) ][ODBC Driver Manager] Data source name not found and no default driver specified
      Ok, I don't think this is that complicated, but I can't get it working right. I could work this fine under PWS and Win98. Having various...
    3. How does the OLEDB driver handle RS Updates?
      I know (now) that using ADO recordsets for updates is a bad idea, and I now longer use them for new pages we create; howevre, I just have a...
    4. IBM Informix OLEDB driver bug
      My code sum a database column whose type is 4 bytes integer Select SUM(col1) From tbl GROUP BY col2 ORDER BY col3 The SUM value can be up to 7...
    5. difference between SQLclient class and Oledb client
      Hi, I am using Access to practice database application developing, thus the namespace system.data.oledb is used instead of system.data.sqlclient,...
  3. #2

    Default Re: Definite difference between using OLEDB and ODBC as the driver

    Laphan wrote:
    > Hi All
    >
    > Some of you may not remember (or even care for that matter ;0)), but I
    > mentioned in a previous post that I had difficulty using the OLEDB for
    > Access connection over the ODBC one because there were gremlins
    > lurking to cock-up my code.
    >
    > Well I've managed to source 2 of these problems and would appreciate
    > it if you could confirm why they are doing the following and more
    > importantly how to correct them:
    >
    > set oCmd=Server.CreateObject("ADODB.Command")
    > set oCmd.ActiveConnection = oConn
    > oCmd.CommandText = "Admin_GetProdList()"
    Why the parentheses? I've never used them for any database ...
    > oCmd.CommandType = 4
    > set oRSv=Server.CreateObject("ADODB.recordset")
    > oRSv.CursorLocation = 3
    > oRSv.open oCmd
    >
    > If I leave in the brackets () after Admin_GetProdList, OLEDB reports
    > an error, but ODBC works fine. If I remove the brackets OLEDB works
    > and ODBC still works. Not a calamity this one, but why is it doing
    > this?
    Not sure about this. Why put the parentheses there in the first place?
    >
    > Set oCmd=Server.CreateObject("ADODB.Command")
    > Set oCmd.ActiveConnection = oConn
    > oCmd.CommandText = "Admin_GetSpecificProduct('" & strProdID & "')"
    > oCmd.CommandType = 4
    > 'Response.Write oCmd.CommandText
    > Set oRSv=Server.CreateObject("ADODB.recordset")
    > oRSv.open oCmd
    >
    > This one is more important as I can't use my stored procs with OLEDB.
    >
    > At present, the above generates the below error on OLEDB, but is fine
    > on ODBC:
    Really? This works with ODBC? It shouldn't - you've set the CommandType to 4
    (adCmdStoredProc), so it should not be recognizing parameters in the
    CommandText. I'll accept your word that it works, I'm just surprised that it
    does. This is not how I would choose to run a stored procedure.
    >
    > Error Type:
    > Microsoft JET Database Engine (0x80040E14)
    > Syntax error in parameters clause. Make sure the parameter exists and
    > that you typed its value correctly.
    > /asp/details.asp, line 698
    >
    > I thought that the ADO coding was exactly the same irrespective of the
    > connection method, but the above appears to be of the contrary?
    Nobody said that. I may have mentioned that the values/constants used to set
    properties of ADO objects do not vary depending on the connection library
    being used. That is still true. In both cases you are setting the
    CommandText property to a string. What is different is how each provider is
    handling that string. The CommandText is being sent off to the ODBC or OLEDB
    library, each of which has its own requirements. It's not a big deal. The
    best way to execute a saved query/stored procedure is to use the
    "procedure-as-native-connection-method" technique. Here is how it would work
    with the above query (you do not need a command object):

    Set oRSv=Server.CreateObject("ADODB.recordset")
    oConn.Admin_GetSpecificProduct strProdID, oRSv

    If your query does not return records, then don't use the recordset object:
    oConn.ActionQuery parm1,parm2, ..., parmN

    HTH,
    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  4. #3

    Default Re: Definite difference between using OLEDB and ODBC as the driver

    Bob

    Thanks for your reply, but I'm more confused now.

    I've always done Connection code, then Command code and then Recordset code
    (as outlined by Wrox Press), because this seemed to be the neatest and more
    flexible way. I can reuse the same Command object for several transactions
    and then use it against my Recordset object several times without creating
    any more than 1 Command Object and 1 Recordset Object.

    Calling a non-parameter SProc with the parentheses is no issue to me, I will
    leave them off, but performing 'parameter-laden' SProcs in the way you have
    described has bamboozled me.

    I'm also confused that you are surprised that the parameters work when I set
    the CommandType to 4. I was of the understanding that 4 is for SProcs and I
    simply add the parameters that I want to send to this SProc as per my
    example.

    As I'd like to keep the method I currently use, do I take it that my line
    should be as follows:

    oCmd.CommandText = Admin_GetSpecificProduct strProdID

    Thanks for your assistance and patience.

    Rgds

    Robbie

    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:eb41$Hb9DHA.3176@TK2MSFTNGP11.phx.gbl...
    Laphan wrote:
    > Hi All
    >
    > Some of you may not remember (or even care for that matter ;0)), but I
    > mentioned in a previous post that I had difficulty using the OLEDB for
    > Access connection over the ODBC one because there were gremlins
    > lurking to cock-up my code.
    >
    > Well I've managed to source 2 of these problems and would appreciate
    > it if you could confirm why they are doing the following and more
    > importantly how to correct them:
    >
    > set oCmd=Server.CreateObject("ADODB.Command")
    > set oCmd.ActiveConnection = oConn
    > oCmd.CommandText = "Admin_GetProdList()"
    Why the parentheses? I've never used them for any database ...
    > oCmd.CommandType = 4
    > set oRSv=Server.CreateObject("ADODB.recordset")
    > oRSv.CursorLocation = 3
    > oRSv.open oCmd
    >
    > If I leave in the brackets () after Admin_GetProdList, OLEDB reports
    > an error, but ODBC works fine. If I remove the brackets OLEDB works
    > and ODBC still works. Not a calamity this one, but why is it doing
    > this?
    Not sure about this. Why put the parentheses there in the first place?
    >
    > Set oCmd=Server.CreateObject("ADODB.Command")
    > Set oCmd.ActiveConnection = oConn
    > oCmd.CommandText = "Admin_GetSpecificProduct('" & strProdID & "')"
    > oCmd.CommandType = 4
    > 'Response.Write oCmd.CommandText
    > Set oRSv=Server.CreateObject("ADODB.recordset")
    > oRSv.open oCmd
    >
    > This one is more important as I can't use my stored procs with OLEDB.
    >
    > At present, the above generates the below error on OLEDB, but is fine
    > on ODBC:
    Really? This works with ODBC? It shouldn't - you've set the CommandType to 4
    (adCmdStoredProc), so it should not be recognizing parameters in the
    CommandText. I'll accept your word that it works, I'm just surprised that it
    does. This is not how I would choose to run a stored procedure.
    >
    > Error Type:
    > Microsoft JET Database Engine (0x80040E14)
    > Syntax error in parameters clause. Make sure the parameter exists and
    > that you typed its value correctly.
    > /asp/details.asp, line 698
    >
    > I thought that the ADO coding was exactly the same irrespective of the
    > connection method, but the above appears to be of the contrary?
    Nobody said that. I may have mentioned that the values/constants used to set
    properties of ADO objects do not vary depending on the connection library
    being used. That is still true. In both cases you are setting the
    CommandText property to a string. What is different is how each provider is
    handling that string. The CommandText is being sent off to the ODBC or OLEDB
    library, each of which has its own requirements. It's not a big deal. The
    best way to execute a saved query/stored procedure is to use the
    "procedure-as-native-connection-method" technique. Here is how it would work
    with the above query (you do not need a command object):

    Set oRSv=Server.CreateObject("ADODB.recordset")
    oConn.Admin_GetSpecificProduct strProdID, oRSv

    If your query does not return records, then don't use the recordset object:
    oConn.ActionQuery parm1,parm2, ..., parmN

    HTH,
    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"



    Astra Guest

  5. #4

    Default Re: Definite difference between using OLEDB and ODBC as the driver

    Astra wrote:
    > Bob
    >
    > Thanks for your reply, but I'm more confused now.
    >
    > I've always done Connection code, then Command code and then
    > Recordset code (as outlined by Wrox Press),
    The Wrox books are good, but not complete. and they don't alway show the
    most efficient ways to do things.
    > because this seemed to be
    > the neatest and more flexible way. I can reuse the same Command
    > object for several transactions and then use it against my Recordset
    > object several times without creating any more than 1 Command Object
    > and 1 Recordset Object.
    Well, now you see a simpler method. No reason to be confused. There are
    several ways to do most tasks in ADO. Instead of creating a command object,
    use the same connection and recordset objects over and over. Much cleaner:

    set cn=createobject ...
    set rs=createobject ...
    parm=<some value>
    cn.sproc parm, rs
    'process the results
    rs.close
    parm=<some new value>
    cn.sproc parm, rs

    ADO creates a command object behind the scenes when you do this.
    >
    > Calling a non-parameter SProc with the parentheses is no issue to me,
    > I will leave them off, but performing 'parameter-laden' SProcs in the
    > way you have described has bamboozled me.
    That your technique works has bamboozled me. For some reason, ADO is
    ignoring the fact that you set the commandtype to 4. In your technique you
    are creating a dynamic sql statement (any time you use "&" to create a
    statement, you are creating a dynamic sql statement, even when part of the
    statement involves running a stored procedure) and executing it, so your
    commandtype should be 1 (adCmdText). For some reason, ADO is ignoring your
    commandtype setting when using the ODBC driver ... I wonder if that's
    because your ODBC driver is a Jet 3.51 driver. Jet 3.51 did not support
    stored procedures.

    By using dynamic sql to execute your stored procedure, you are losing two of
    the benefits of using a stored procedure:

    1. strong data typing of your parameter values - this can prevent errors and
    allows data to be passed across the network and cross process boundaries
    more efficiently

    2. Not an issue with Access, but with SQL Server: protection against sql
    injection ([url]http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23[/url])
    >
    > I'm also confused that you are surprised that the parameters work
    > when I set the CommandType to 4. I was of the understanding that 4
    > is for SProcs and I simply add the parameters that I want to send to
    > this SProc as per my example.
    No. You are supposed to use the Parameters collection to pass parameters to
    a stored procedure when you set the commandtype to 4. See my reply in the
    other thread for an example.
    >
    > As I'd like to keep the method I currently use, do I take it that my
    > line should be as follows:
    >
    > oCmd.CommandText = Admin_GetSpecificProduct strProdID
    >
    No, that would not work. You need to supply a string containing simply the
    name of the procedure to CommandText when you set the CommandType to 4.
    Since you did not put quotes around the above text, you would get an error.
    I gave an example of the correct way to pass parameters via the Parameters
    collection in the other thread.

    With Access, however, I still suggest eschewing the Command object and use
    the "procedure-as-cnnection-method" technique.

    The only time I advise explicitly creating a Command object is when your SQL
    Server stored procedure has output parameters or you need to read the value
    of the Return parameter.

    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  6. #5

    Default Re: Definite difference between using OLEDB and ODBC as the driver

    Geees Bob, have you been on something today!!!

    Replies like lightning!!

    Much appreciated though.

    This info has been really insightful and I'll try and keep to these
    guidelines.

    What's eschewing mean anyway??

    Rgds

    Laphan


    Bob Barrows <reb01501@NOyahoo.SPAMcom> wrote in message
    news:eIddC6h9DHA.440@TK2MSFTNGP10.phx.gbl...
    Astra wrote:
    > Bob
    >
    > Thanks for your reply, but I'm more confused now.
    >
    > I've always done Connection code, then Command code and then
    > Recordset code (as outlined by Wrox Press),
    The Wrox books are good, but not complete. and they don't alway show the
    most efficient ways to do things.
    > because this seemed to be
    > the neatest and more flexible way. I can reuse the same Command
    > object for several transactions and then use it against my Recordset
    > object several times without creating any more than 1 Command Object
    > and 1 Recordset Object.
    Well, now you see a simpler method. No reason to be confused. There are
    several ways to do most tasks in ADO. Instead of creating a command object,
    use the same connection and recordset objects over and over. Much cleaner:

    set cn=createobject ...
    set rs=createobject ...
    parm=<some value>
    cn.sproc parm, rs
    'process the results
    rs.close
    parm=<some new value>
    cn.sproc parm, rs

    ADO creates a command object behind the scenes when you do this.
    >
    > Calling a non-parameter SProc with the parentheses is no issue to me,
    > I will leave them off, but performing 'parameter-laden' SProcs in the
    > way you have described has bamboozled me.
    That your technique works has bamboozled me. For some reason, ADO is
    ignoring the fact that you set the commandtype to 4. In your technique you
    are creating a dynamic sql statement (any time you use "&" to create a
    statement, you are creating a dynamic sql statement, even when part of the
    statement involves running a stored procedure) and executing it, so your
    commandtype should be 1 (adCmdText). For some reason, ADO is ignoring your
    commandtype setting when using the ODBC driver ... I wonder if that's
    because your ODBC driver is a Jet 3.51 driver. Jet 3.51 did not support
    stored procedures.

    By using dynamic sql to execute your stored procedure, you are losing two of
    the benefits of using a stored procedure:

    1. strong data typing of your parameter values - this can prevent errors and
    allows data to be passed across the network and cross process boundaries
    more efficiently

    2. Not an issue with Access, but with SQL Server: protection against sql
    injection ([url]http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23[/url])
    >
    > I'm also confused that you are surprised that the parameters work
    > when I set the CommandType to 4. I was of the understanding that 4
    > is for SProcs and I simply add the parameters that I want to send to
    > this SProc as per my example.
    No. You are supposed to use the Parameters collection to pass parameters to
    a stored procedure when you set the commandtype to 4. See my reply in the
    other thread for an example.
    >
    > As I'd like to keep the method I currently use, do I take it that my
    > line should be as follows:
    >
    > oCmd.CommandText = Admin_GetSpecificProduct strProdID
    >
    No, that would not work. You need to supply a string containing simply the
    name of the procedure to CommandText when you set the CommandType to 4.
    Since you did not put quotes around the above text, you would get an error.
    I gave an example of the correct way to pass parameters via the Parameters
    collection in the other thread.

    With Access, however, I still suggest eschewing the Command object and use
    the "procedure-as-cnnection-method" technique.

    The only time I advise explicitly creating a Command object is when your SQL
    Server stored procedure has output parameters or you need to read the value
    of the Return parameter.

    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"




    Laphan Guest

  7. #6

    Default Re: Definite difference between using OLEDB and ODBC as the driver

    Laphan wrote:
    > Geees Bob, have you been on something today!!!
    >
    > Replies like lightning!!
    >
    > Much appreciated though.
    >
    > This info has been really insightful and I'll try and keep to these
    > guidelines.
    >
    > What's eschewing mean anyway??
    >
    :-) Oops. Forgot you weren't a native English speaker ...

    Eschewing = Avoiding, as in, not using.

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139