Sql server 带Windows身份验证的VB.NET ODBC连接

Sql server 带Windows身份验证的VB.NET ODBC连接,sql-server,vb.net,dns,odbc,Sql Server,Vb.net,Dns,Odbc,我正在使用Windows Server数据中心。我正在使用.Net 4.0版开发VB.Net 2010快速版 我在VB.Net上与SQL Server建立ODBC连接时遇到问题 这是我连接数据库的代码片段 Imports System.Data.Odbc Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles But

我正在使用Windows Server数据中心。我正在使用.Net 4.0版开发VB.Net 2010快速版

我在VB.Net上与SQL Server建立ODBC连接时遇到问题

这是我连接数据库的代码片段

Imports System.Data.Odbc

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cn As Odbc.OdbcConnection
        cn = New Odbc.OdbcConnection("DRIVER={SQL Server};SERVER=<machine_name>\SQLEXPRESS;UID=<machine_name>\<windows_username>;" & _
                               "PWD=<windows_password>;DATABASE=testdb;")

        Dim mystring As String = "select * from Customers"
        Dim cmd As Odbc.OdbcCommand = New Odbc.OdbcCommand(mystring)
        cn.Open()
        MsgBox("Connected")
        cn.Close()
    End Sub
End Class
我已签入32位和64位DNS,指定的DNS名称在两个版本中都可用

我错在哪里建立联系?指定连接字符串时有问题吗?如果是这样,请建议使用正确的连接字符串在VB.Net 2010 Express Edition中建立SQL Server的ODBC连接。


DSN参见第4点
将以下代码添加到DSN按钮: Dim cn作为ODBC连接 cn=新OdbcConnection(“dsn=MyDSN;uid=sa;pwd=myPassword;”) Dim mystring As String=“选择*来自客户” Dim cmd As OdbcCommand=新OdbcCommand(mystring) cn.Open() MsgBox(“已连接”) cn.Close()

您正在使用SQL Server 2012 Express吗?不要错过服务器名称语法Servername\SQLEXPRESS,在该语法中,您可以将Servername替换为SQL server 2012 Express安装所在的计算机的名称


您的连接字符串指定了
UID
PWD
。这会告诉SQL Server您正在尝试使用SQL身份验证(与Windows身份验证相反)进行连接。从连接字符串中删除
UID
PWD
,并替换为
integratedsecurity=True
integratedsecurity
参数有效。它使用问题中指定的第一个连接字符串连接到SQL Server数据库。但我仍然得到
数据源名称未找到…
通过DNS连接连接时出错。我提供的连接字符串是
DNS=testsource;综合安全=真实问题出在哪里?我正在使用SQL Server 2008。我想通过DNS建立ODBC连接。可以在Windows Server数据中心上通过ODBC进行DNS连接吗?你是说DSN?控制面板\所有控制面板项目\管理工具,它们进行连接。我不会这样做,我会管理一切从我的代码。。。这将共享您的所有数据库此Windows Server数据中心不是共享主机?是,抱歉DSN。我不知道Windows Server数据中心是否为共享主机。是的,通过SQL Server凭据,我可以连接,但我也想使用DSN名称进行尝试。VB.Net是否不能通过DSN连接SQL Server?这里可能是示例DSN,有2个链接,请参见第4点了解DSN No luck。微软支持论坛的链接非常古老。因此,它对我没有用处,因为我对.NET4.0有异议。第二个环节不起作用。
ERROR [28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '<machine_name>\<windows_username>'.
DRIVER={SQL Server};DNS=<DNS_name>;UID=<windows_username>;PWD=<windows_password>;
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
 Standard security
    Driver={SQL Server Native Client 11.0};Server=myServerAddress;
    Database=myDataBase;Uid=myUsername;Pwd=myPassword;
-----------------------------------

Trusted Connection
    Driver={SQL Server Native Client 11.0};Server=myServerAddress;
    Database=myDataBase;Trusted_Connection=yes;
------------------------

Connecting to an SQL Server instance
The syntax of specifying the server instance in the value of the server key is the same for all connection strings for SQL Server.
Driver={SQL Server Native Client 11.0};Server=myServerName\theInstanceName;
Database=myDataBase;Trusted_Connection=yes;

------------------
Prompt for username and password
This one is a bit tricky. First you need to set the connection object's Prompt property to adPromptAlways. Then use the connection string to connect to the database.
oConn.Properties("Prompt") = adPromptAlways

oConn.Open "Driver={SQL Server Native Client 11.0};Server=myServerAddress;Database=myDataBase;"
------------------

Enable MARS
    Driver={SQL Server Native Client 11.0};Server=myServerAddress;
    Database=myDataBase;Trusted_Connection=yes;MARS_Connection=yes;
-------------------

Encrypt data sent over network
Driver={SQL Server Native Client 11.0};Server=myServerAddress;
Database=myDataBase;Trusted_Connection=yes;Encrypt=yes;

-------------------

Attach a database file on connect to a local SQL Server Express instance
    Driver={SQL Server Native Client 11.0};Server=.\SQLExpress;
    AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;

------------------------------
Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
    Driver={SQL Server Native Client 11.0};Server=.\SQLExpress;
    AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;
    Trusted_Connection=Yes;
-----------------
Database mirroring
If you connect with ADO.NET or the SQL Native Client to a database that is being mirrored, your application can take advantage of the drivers ability to automatically redirect connections when a database mirroring failover occurs. You must specify the initial principal server and database in the connection string and the failover partner server.
    Driver={SQL Server Native Client 11.0};Server=myServerAddress;
     Failover_Partner=myMirrorServerAddress;Database=myDataBase;
    Trusted_Connection=yes;
---------------