简体   繁体   English

SQL数据读取器SQL Server核心实现

[英]SQL Data Reader SQL Server core implementation

while i am learning core of System.Data i tried reading MSDN Core implementation code. 虽然我正在学习System.Data核心,但我尝试阅读MSDN Core实现代码。

in the same way i could call some low level system dll (win32) to read hdd drive info i was trying to test and learn from system data SQL through the above MSDN link, as i am trying to break it down i couldn't find the entry point. 以同样的方式,我可以调用一些低级系统DLL(win32)来读取硬盘驱动器信息我试图通过上面的MSDN链接测试和学习系统数据SQL,因为我试图打破它我找不到入口点。 my question is: 我的问题是:

what is the minimal code required to connect to SQL SERVER and return some data ? 连接到SQL SERVER并返回一些数据所需的最小代码是什么?

*either with c# preferred or c++ (if there's noticeably less overhead) *使用c# preferredc++ (如果明显减少开销)

Edit: using only some parts From the System.Data SqlDataReader Rather than whole class. 编辑:仅使用一些部分来自System.Data SqlDataReader而不是整个类。

System.Data.SqlClient (.NET Provider for SQL Server) is a low-level "DLL". System.Data.SqlClient(SQL Server的.NET提供程序)是一个低级“DLL”。 It communicates with SQL Server using the low-level TDS protocol similarly to ODBC and OLEDB. 它使用低级TDS协议与SQL Server进行通信,类似于ODBC和OLEDB。 The difference is SqlClient is a managed provider whereas ODBC drivers and OLEDB providers are native (unmanaged). 区别在于SqlClient是托管提供程序,而ODBC驱动程序和OLEDB提供程序是本机(非托管)。 The unmanaged driver/providers provide a call-level interface and COM interface respectively, which is intended to be used from native code like unmanaged C++. 非托管驱动程序/提供程序分别提供调用级接口和COM接口,旨在从非托管C ++等本机代码中使用。

All these providers/drivers communicate with SQL Server using the low-level TDS protocol. 所有这些提供程序/驱动程序都使用低级TDS协议与SQL Server进行通信。 The TDS protocol itself is not directly exposed. TDS协议本身不直接暴露。 System.Data.SqlClient.SqlDataReader is the lowest level data access from managed code and provides the highest performance for .NET applications. System.Data.SqlClient.SqlDataReader是托管代码的最低级别数据访问,为.NET应用程序提供最高性能。

Here is a link to the beginner's guide to connecting to SQL Server with C#: 以下是使用C#连接到SQL Server的初学者指南的链接:

http://www.codeproject.com/Articles/4416/Beginners-guide-to-accessing-SQL-Server-through-C http://www.codeproject.com/Articles/4416/Beginners-guide-to-accessing-SQL-Server-through-C

But you should make sure to properly separate code-responsibility so that you're not rewriting the same code all over the place. 但是你应该确保正确地分离代码责任,这样你就不会在整个地方重写相同的代码。 Have a class that interfaces with the database (dataaccess layer) so you can just call it from all of your business objects and static classes. 有一个与数据库(dataaccess层)接口的类,因此您可以从所有业务对象和静态类中调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM