如果我没有安装本机客户端,Visual Studio 2010 如何连接到 SQL Server 2008?
我在 Windows 7 上安装了 MS VS 2010,但是没有安装 SQL Server Native 客户端。
加载 Visual Studio 后,我单击菜单“数据”/“Transact-SQL 编辑器”/“新建查询连接”。
将显示 SQL Server 2008 R2 登录对话框,我键入服务器名称,选择 SQL Server 身份验证,键入用户名和密码,然后单击连接。连接已建立,编辑器窗口出现,我已准备好查询!
据我所知,SQL Server 2008本机客户端文件是sqlncli10.dll、sqlnclir10.rll。我确实在整个硬盘中搜索了这些文件,但没有找到。
那么,如果我没有安装本机客户端,Visual Studio 2010 如何连接到 SQL Server 2008?
连接到 SQL Server 2008 时,VS 2010 是否使用 .NET Framework 程序集?
I have MS VS 2010 installed on my Windows 7 but, I don't have the SQL Server Native client installed in it.
After loading Visual Studio I do click menu Data / Transact-SQL Editor / New Query Connection.
The SQL Server 2008 R2 login dialog will show up, I type server name, select SQL Server authentication, type username and password and click connect. The connection is established and an editor window shows up and I'm ready to query!
I understand the SQL Server 2008 native client files are sqlncli10.dll, sqlnclir10.rll. I did search for these files in my entire hard drive and they weren't found.
So, how is Visual Studio 2010 connecting to SQL Server 2008 if I don't have the native client installed?
Is VS 2010, when connecting to SQL Server 2008, using .NET Framework assemblies?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.NET Framework 已包含 Sql Server(和其他)数据库客户端。
看看System.Data.SqlClient
The .NET Framework already contains the Sql Server (and other) Database clients.
Have a look at System.Data.SqlClient
如果未安装本机客户端,则在通过菜单“数据/Transact-SQL 编辑器/新建查询连接”进行连接时,Visual Studio 2010 将使用 .NET Framework 版本 4.0 连接到 SQL Server 2008 R2。
我验证了它正在加载程序集 System.Data.dll(位于 C:\Windows\Microsoft.NET\Framework\v4.0.30319 下)以建立与服务器的连接。
我还没有安装 SQL Server 2008 R2 的本机客户端 10.0,现在也没有使用它,但是如果安装了,应该可以在以下位置找到本机客户端文件(sqlncli10.dll、sqlnclir10.rll 和 s10ch_sqlncli.chm
)作为 SQL Server 安装的一部分进行安装。
还有一个名为 sqlncli.msi 的可再发行安装程序,可以在 SQL Server 安装 CD 上的
安装详细信息参考
http://msdn.microsoft.com/en-us/library/ms131321.aspx
以及 SQL Server 2008 的参考R2 本机客户端功能
http://msdn.microsoft.com/en-us/library /ms131456.aspx
If NO native client is installed, Visual Studio 2010 is using the .NET Framework version 4.0 to connect to SQL Server 2008 R2 when connecting through menu Data/Transact-SQL Editor/New Query Connection.
I verified and it is loading assembly System.Data.dll (located under C:\Windows\Microsoft.NET\Framework\v4.0.30319) to establish the connection to the server.
I have not installed the Native client 10.0 for SQL Server 2008 R2 and I'm not using it right now but, if installed, the native client files (sqlncli10.dll, sqlnclir10.rll, and s10ch_sqlncli.chm) should be found under
which are installed as part of the SQL Server installation.
There is also a redistributable installation program named sqlncli.msi, which should be found on the SQL Server installation CD under
The reference for installation details
http://msdn.microsoft.com/en-us/library/ms131321.aspx
And the reference for the SQL Server 2008 R2 Native Client Features
http://msdn.microsoft.com/en-us/library/ms131456.aspx
这里的关键信息是:
您不需要在客户端计算机(在本例中是 Visual Studio 所在的开发盒)上安装 SQL Server Native Client,以便使用 ADO.Net 的应用程序连接到 SQL Server 。
原因正如 @dknaack 所说:.Net 框架包含建立连接所需的代码。它包含在 System.Data.SqlClient 中。
另一方面,非托管应用程序使用 SQL Native Client 通过 OleDB 或 ODBC 提供程序连接到 SQL Server。
简而言之:
System.Data.SqlClient - 用于从托管代码到 SQL Server 的连接,即 ADO.Net 连接
SQL Server Native Client - 用于从非托管代码到 SQL Server 的连接
虽然您可以使用 SQL Server Native Client 从托管应用程序连接到 SQL Server,但不建议这样做:
参考:
https://learn.microsoft.com/en-us/sql/relational-databases/native-client/sql-server-native-client-programming?view=sql-server-2017
https://learn.microsoft.com/en-us/sql/relational-databases/native-client/applications/using-ado-with-sql-server-native-client?view=sql-server-2017
The key piece of information here is:
You do not need to install SQL Server Native Client on your client machine (in this case your dev box where Visual Studio is), in order for an application using ADO.Net, to connect to SQL Server.
The reason is as @dknaack said: the .Net framework contains the code required to make the connection. This is contained in System.Data.SqlClient.
SQL Native Client on the other hand is used by unmanaged applications to connection to SQL Server via either OleDB or ODBC providers.
In short:
System.Data.SqlClient - used for connections from managed code to SQL Server i.e an ADO.Net connection
SQL Server Native Client - used for connections from unmanaged code to SQL Server
Whilst you CAN connect to SQL Server from a managed app using SQL Server Native Client, it is not a recommended practice:
References:
https://learn.microsoft.com/en-us/sql/relational-databases/native-client/sql-server-native-client-programming?view=sql-server-2017
https://learn.microsoft.com/en-us/sql/relational-databases/native-client/applications/using-ado-with-sql-server-native-client?view=sql-server-2017