简体   繁体   English

似乎无法通过C#连接到我的MySQL数据库

[英]Can't seem to connect to my MySQL database via c#

like the title says, I cannot connect to my database via c#, I get the following exception when I try to open an connection: 如标题所示,我无法通过c#连接到我的数据库,尝试打开连接时出现以下异常:

Unable to connect to any of the specified MySQL hosts 无法连接到任何指定的MySQL主机

But I can connect no problem with PHP using the exact same login info. 但是我可以使用完全相同的登录信息将PHP连接到任何位置。

EDIT I am just changing databases. 编辑我只是在更改数据库。 This connection string has worked for 2 years using a different database. 使用不同的数据库,此连接字符串已经使用了2年。 I have tried it using Server, instead of Data Source, and UID/User ID instead of UserID with the same result 我已经使用服务器而不是数据源尝试了它,并且使用UID /用户ID而不是用户ID尝试了相同的结果

C#: C#:

ProjectDBC = new MySqlConnection("Data Source=combinedsystems.ca;Database=combined_project;UserID=xxxxx;Password=xxxxx;");

PHP: PHP:

$db_user = "xxxxx";
$db_pass = "xxxxx";
$db_database = "combined_project"; 
$db_host = "combinedsystems.ca";

$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_database);

It is probably something easy, but I just can't figure it out right now. 这可能很容易,但是我现在无法弄清楚。 Any ideas? 有任何想法吗?

The database is hosted through hosteasysolutions.com if that makes any difference 如果有任何区别,则通过hosteasysolutions.com托管数据库。

Your connection string looks wrong... You need to specify Server , Uid and Pwd instead of Data Source , UserID and Password , or specify Data Source , User ID and Password (User ID has a space) 您的连接字符串看起来不正确...您需要指定ServerUidPwd而不是Data SourceUserIDPassword ,或者指定Data SourceUser IDPassword (用户ID带有空格)

Server=combinedsystems.ca;Database=combined_project;Uid=xxxxx;Pwd=xxxxx;

OR 要么

Data Source=combinedsystems.ca;Database=combined_project;User ID=xxxxx;Password=xxxxx;

Check this link for examples. 查看此链接以获取示例。

You don't specify a server, do you? 您没有指定服务器,对吗? I use following string to connect to mysql hosts: 我使用以下字符串连接到mysql主机:

Server=localhost;Database=db;UID=user;Password=pass

尝试在用户和ID之间使用空格,或者仅使用User =或UID =

确保自更改数据库以来,您的项目中没有定义(以某种方式-在某处)两个连接字符串!!!

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

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