Delphi with SQL Server: OLEDB vs. Native Client drivers

前端 未结 8 2484
花落未央
花落未央 2021-02-09 16:13

I have been told that SQL Native Client is supposed to be faster than the OLEDB drivers. So I put together a utility to do a load-test between the two - and am getting

相关标签:
8条回答
  • 2021-02-09 16:58

    While it certainly could be at the database end, I think there is a lot to look at in the overall system - at least your test system. In general, it is hard to do timing if the work you are asking the database to do is very small compared to the overall work. So in general, is the database task a big job or simply the retrieval of one data item? Are you using stored procedures or simple queries? Is your test preparing any stored procedures before running the test? Do you get consistent times each time you run any test in sucession?

    0 讨论(0)
  • 2021-02-09 16:59

    You cannot use the native clients with ADO, as is.

    ADO does not understand the XML SQL Server data type. The field type:

    field: ADOField;
    
    field := recordset.Fields.Items["SomeXmlColumn"];
    

    Attempting to access field.Value throws an EOleException:

    • Source: Microsoft Cursor Engine
    • ErrorCode: 0x80040E21 (E_ITF_0E21)
    • Message: Multiple-step operation generated errors. Check each status value

    The native client drivers (e.g. SQLNCLI, SQLNCLI10, SQLNCLI11) present an Xml data type to ADO as

    field.Type_ = 141 
    

    While the legacy SQLOLEDB driver presents an Xml data type to ADO as adLongVarWChar, a unicode string:

    field.Type_ = 203 //adLongVarWChar
    

    And the VARIANT contained in field.Value is a WideString (technically known as a BSTR):

    TVarData(field.Value).vtype = 8 //VT_BSTR
    

    The solution, as noted by Microsoft:

    Using ADO with SQL Server Native Client

    Existing ADO applications can access and update XML, UDT, and large value text and binary field values using the SQLOLEDB provider. The new larger varchar(max), nvarchar(max), and varbinary(max) data types are returned as the ADO types adLongVarChar, adLongVarWChar and adLongVarBinary respectively. XML columns are returned as adLongVarChar, and UDT columns are returned as adVarBinary. However, if you use the SQL Server Native Client OLE DB provider (SQLNCLI11) instead of SQLOLEDB, you need to make sure to set the DataTypeCompatibility keyword to "80" so that the new data types will map correctly to the ADO data types.

    They also note:

    If you do not need to use any of the new features introduced in SQL Server 2005, there is no need to use the SQL Server Native Client OLE DB provider; you can continue using your current data access provider, which is typically SQLOLEDB.

    0 讨论(0)
  • 2021-02-09 17:02

    I think you should concentrate on optimizing the:

    • sql server engine and database settings
    • your queries
    • your data schema

    Difference in speed between connection libraries is so small, even negligible, that it may cause a very tiny slowdown of systems and in very specific scenarios

    0 讨论(0)
  • 2021-02-09 17:05

    As stated by Microsoft:

    SQL Server Native Client is a stand-alone data access application programming interface (API), used for both OLE DB and ODBC, that was introduced in SQL Server 2005. SQL Server Native Client combines the SQL OLE DB provider and the SQL ODBC driver into one native dynamic-link library (DLL).

    From my understanding, ADO is just an Object Oriented application-level DB layer over OleDB. It will use OleDB in all cases. What changes is the provider used. If you specify the SQLNCLI10 provider, you'll use the latest version of the protocol. If you specify the SQLOLEDB provider, you'll use the generic SQL Server 2000 + protocol.

    As such:

      ADO -> OleDB -> SQLNCLI10 provider -> MS SQL Server (MSSQL 2000, 2005 or 2008 protocol)
      ADO -> OleDB -> SQLOLEDB provider -> MS SQL Server (MSSQL 2000 protocol)
    

    About performance, I think you won't have a big difference. Like always, it will depend on the data processed.

    But it is IMHO recommended to use best fitted provider for your database. Some kind of data (like var(maxchar) or Int64) is told to be best handled. And the SQLNCLI10 provider has been updated, so I guess it is more tuned.

    0 讨论(0)
  • 2021-02-09 17:07
    1. In your question you are mxing OLE and SQL Native Client. Probably you are mean few things in the same time:

      • OLE -> OLEDB, which is obsolescent generic data access technology;
      • OLE -> "SQL Server OLEDB Provider", which is SQL Server 2000 OLEDB provider;
      • SQL Server Native Client, which is SQL Server 2005 and higher client software. And it includes as OLEDB provider, as ODBC driver.
    2. If to talk about OLEDB providers and supported SQL Server versions, then:

      • "SQL Server OLEDB Provider" (SQLOLEDB) supports SQL Server 2000 protocol;
      • "SQL Server Native Client 9" (SQLNCLI) supports SQL Server 2000 and 2005 protocols;
      • "SQL Server Native Client 10" supports SQL Server 2000, 2005 and 2008 protocols.

      You did not sayd what SQL Server version you are using. In general, best is to use SQL Server OLEDB provider corresponding to your SQL Server version. Otherwise you can run into incompatibility between server and client versions.

    3. Abstractly comparing, I can only speculate about differences between SQLNCLI and SQLOLEDB:

      • One is more correctly uses server protocol;
      • One is using more advanced protocol features;
      • One performs more processing, what heps to handle more situations;
      • One uses more generic / optimized data represenation.

      Without correct benchmark application and environment it is hard to accept your comparision results, because they may depend on multiple factors.

    0 讨论(0)
  • 2021-02-09 17:08

    Short answer:
    It doesn't matter.

    Long answer:
    The difference in performance between the 2 client libs is relatively negligible compared to the Server execution + Network data transfer, which is what you are mostly measuring, hence the inconclusive test data. There is a good chance that you use the same low level layer in both cases anyway with only a minor difference in indirection on top of it.

    As a matter of fact, if your tests show no visible difference, it just proves that the slowness is not related with the choice of the client lib and optimization should be searched elsewhere.

    For your present test, you should use the SQL Profiler to measure the queries execution time on the Server at the same time you run your test, you would see that they vary also quite a bit. Subtracting those numbers from the test end results would give you the timing for the bundle Client time + Network transfer.

    Network performance is quite variable and has more impact on your test than you would think. Try having someone streaming video at the same time you run your test and you will see... (Have had that with my former company; tuning the SQL was not the answer in this case )

    0 讨论(0)
提交回复
热议问题