1

我在使用 c# System.Data.SqlClient 连接到我的本地数据库时遇到了一些问题。

信息:

  • 数据库参数:名称:baza主机:localhost实例:baza端口:3306架构:world
  • 我的连接字符串:@"server=localhost\baza;password=pass;User Id=root;database=world;Persist Security Info=True"
  • 使用:c#、System.Data.SqlClient、MySQL Workbench
  • 防火墙关闭
  • 与 JDBC 成功连接,因此服务器正在工作

JDBC参数:

String url = "jdbc:mysql://localhost:3306/";
String driver = "com.mysql.jdbc.Driver";
String dbName = "world";
String username = "root";
String pass = "pass";

问题:

  • 当我使用 conn.Open(); 这发生 =>(提供者:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)

试过:

我不知道该怎么办...某事可能与服务器名称有关。

编辑:代码:

string connstr = @"Data Source=localhost\baza;password=qspass;User Id=root;"+
    "Initial Catalog=world;Persist Security Info=True";

Console.WriteLine(connstr);

SqlConnection conn = new SqlConnection(conbuild.ConnectionString);
conn.Open();

Console.WriteLine("YO!");
Some more code...

从来没有达到过哟!:P

4

1 回答 1

2

我想我应该把我的答案放在答案部分,而不是评论:)

我从您的 JDBC 连接字符串中看到您使用的是 MySQL 而不是 SQL Server。

System.Data.SqlClient 命名空间是 SQL Server 的 .NET Framework 数据提供程序,而不是 MySQL。

如果您使用的是 MySQL,则需要使用此处提供的 MySQL ADO.NET 驱动程序:

下载连接器/网络

于 2013-04-05T10:36:06.197 回答