sqlserver OpenRowSet 对应的三种数据库驱动
在使用sqlserver数据库的OpenRowSet函数时,会遇到三种驱动方式: 1. MSDASQL驱动 SELECT TOP 10 * FROM OPENROWSET('MSDASQL', 'DRIVER={SQL Server};SERVER=xxx;UID=xx;PWD=xxx;', 'select * from AdventureWorks.HumanResources.Employee') 2. SQLNCLI驱
在使用sqlserver数据库的OpenRowSet函数时,会遇到三种驱动方式:
1. MSDASQL驱动
SELECT TOP 10 *
FROM OPENROWSET('MSDASQL', 'DRIVER={SQL Server};SERVER=xxx;UID=xx;PWD=xxx;', 'select * from AdventureWorks.HumanResources.Employee')
2. SQLNCLI驱动
SELECT TOP 10 *
FROM OPENROWSET('SQLNCLI', 'SERVER=xxx;UID=xx;PWD=xxxxx;', 'select * from AdventureWorks.HumanResources.Employee')
3. SQLOLEDB驱动
SELECT TOP 10 *
FROM OpenRowSet('SQLOLEDB', 'xxx'; 'xx'; 'xxx', AdventureWorks.HumanResources.Employee)
先看一下定义
MSDASQL:Microsoft OLE DB Provider for ODBC Drivers
允许在 OLEDB 和 ADO(它在内部使用 OLEDB)上构建的应用程序通过 ODBC 驱动程序访问数据源的技术。
MSDASQL 是用于连接到 ODBC(而不是数据库)的 OLEDB 访问接口。
SQLOLEDB :Microsoft OLE DB Provider for SQL Server,可以看出来SQLOLEDB是连接到数据库sqlserver,而不是ODBC驱动
SQLNCLI10(SQLNCLI):SQL Server Native Client 10.0
SQL Server Native Client的定义:
SQL Server Native Client 是在 SQL Server 2005 中引入的用于 OLE DB 和 ODBC 的独立数据访问应用程序编程接口 (API)。SQL Server Native Client 将 SQL OLE DB 访问接口和 SQL ODBC 驱动程序组合成一个本机动态链接库 (DLL)。为了利用在 SQL Server 2005以及以上的版本的新功能,比如多个活动结果集 (MARS)、查询通知、用户定义类型 (UDT) 或新的 xml 数据类型,那些使用 ActiveX Data Objects (ADO) 的现有应用程序应当使用 SQL Server Native Client OLE DB 访问接口作为其数据访问接口。
如果不需要使用在 SQL Server 2005 及其以后的版本中引入的任何新功能,则不需要使用 SQL Server Native Client OLE DB 访问接口;您可以继续使用当前数据访问接口(通常是 SQLOLEDB)。如果要增强现有应用程序的功能,并且需要使用在 SQL Server 2005 及其以后的版本中引入的新功能,则应当使用 SQL Server Native Client OLE DB 访问接口。
附上 OPENROWSET 语法格式
OPENROWSET <strong>(</strong> { <strong>'</strong><em>provider_name</em><strong>'</strong> <strong>,</strong> { <strong>'</strong><em>datasource</em><strong>'</strong> <strong>;</strong> <strong>'</strong><em>user_id</em><strong>'</strong> <strong>;</strong> <strong>'</strong><em>password</em><strong>'</strong> | <strong>'</strong><em>provider_string</em><strong>' </strong>} <strong>,</strong> { [ <em>catalog</em><strong>.</strong> ] [ <em>schema</em><strong>. </strong>] <em>object</em> | <strong>'</strong><em>query</em><strong>'</strong> } | BULK <strong>'</strong><em>data_file</em><strong>'</strong> <strong>,</strong> { FORMATFILE <strong>=</strong> <strong>'</strong><em>format_file_path</em><strong>'</strong> [ <bulk_options> ] | SINGLE_BLOB | SINGLE_CLOB | SINGLE_NCLOB } } <strong>)</strong> <bulk_options> ::= [ <strong>,</strong> CODEPAGE <strong>=</strong> { <strong>'</strong>ACP<strong>'</strong> | <strong>'</strong>OEM<strong>'</strong> | <strong>'</strong>RAW<strong>'</strong> | <strong>'</strong><em>code_page</em><strong>'</strong> } ] [ <strong>,</strong> ERRORFILE <strong>=</strong> <strong>'</strong><em>file_name</em><strong>'</strong> ] [ <strong>,</strong> FIRSTROW <strong>=</strong> f<em>irst_row </em>] [ <strong>,</strong> LASTROW <strong>=</strong> la<em>st_row </em>] [ <strong>,</strong> MAXERRORS <strong>=</strong> m<em>aximum_errors </em>] [ <strong>,</strong> ROWS_PER_BATCH <strong>=</strong> <em>rows_per_batch </em>] <br><br>[ <strong>,</strong> ORDER ( { column [ ASC | DESC ] } [ <strong>,</strong>...<em>n</em> ] ) [ UNIQUE ] </bulk_options></bulk_options>
参照:http://www.cnblogs.com/w-y-f/archive/2012/05/07/2488474.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

The location where the Navicat database configuration files are stored varies by operating system: Windows: The user-specific path is %APPDATA%\PremiumSoft\Navicat\macOS: The user-specific path is ~/Library/Application Support/Navicat\Linux: The user-specific path is ~/ .config/navicat\The configuration file name contains the connection type, such as navicat_mysql.ini. These configuration files store database connection information, query history, and SSH settings.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

The format of the Navicat connection URL is: protocol://username:password@host:port/database name? Parameters, which contain the information required for the connection, including protocol, username, password, hostname, port, database name and optional parameter.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.
