没有 Windows 身份验证的 MS SQL ODBC 连接
MS SQL ODBC Connection with NO Windows Authentication
我正在尝试使用 ODBC 连接到 MS SQL,但一直收到
"Login failed for user 'User-PC\User'" 错误。
web.config
<add name="SQLDbConnection" connectionString="Server=127.0.0.1; Database=HMS; Integrated Security=false; User Id=sa; password=root" providerName="System.Data.Odbc "/>
C#
string query = "...";
OdbcConnection msSQLConnection = new OdbcConnection(strConnection);
OdbcCommand command = new OdbcCommand(query, msSQLConnection);
command.Connection.Open();
我试过使用下面的,没问题。知道如何让 ODBC 工作吗?
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLDbConnection"].ToString()))
{
SqlCommand cmd = new SqlCommand("SELECT COMPANY_ID from COMPANY", cn);
cn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
rdr.Read();
}
SQL 连接和 ODBC 连接不使用相同的连接字符串。对于 ODBC 连接,您需要指定驱动程序。
对于 SQL 服务器 2012:
Driver={SQL Server Native Client 11.0};Server=127.0.0.1;Database=HMS;Uid=sa;Pwd=root;
你应该使用这样的东西:
DRIVER={MySQL ODBC 3.51 Driver}; SERVER=127.0.0.1; DATABASE=HMS; USER=sa; PASSWORD=root;
那就到这里看看吧:OBDC example
然后在这里:Connection strings
我正在尝试使用 ODBC 连接到 MS SQL,但一直收到 "Login failed for user 'User-PC\User'" 错误。
web.config
<add name="SQLDbConnection" connectionString="Server=127.0.0.1; Database=HMS; Integrated Security=false; User Id=sa; password=root" providerName="System.Data.Odbc "/>
C#
string query = "...";
OdbcConnection msSQLConnection = new OdbcConnection(strConnection);
OdbcCommand command = new OdbcCommand(query, msSQLConnection);
command.Connection.Open();
我试过使用下面的,没问题。知道如何让 ODBC 工作吗?
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLDbConnection"].ToString()))
{
SqlCommand cmd = new SqlCommand("SELECT COMPANY_ID from COMPANY", cn);
cn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
rdr.Read();
}
SQL 连接和 ODBC 连接不使用相同的连接字符串。对于 ODBC 连接,您需要指定驱动程序。
对于 SQL 服务器 2012:
Driver={SQL Server Native Client 11.0};Server=127.0.0.1;Database=HMS;Uid=sa;Pwd=root;
你应该使用这样的东西:
DRIVER={MySQL ODBC 3.51 Driver}; SERVER=127.0.0.1; DATABASE=HMS; USER=sa; PASSWORD=root;
那就到这里看看吧:OBDC example 然后在这里:Connection strings