Toadums
Toadums

Reputation: 2812

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:

Unable to connect to any of the specified MySQL hosts

But I can connect no problem with PHP using the exact same login info.

EDIT I am just changing databases. This connection string has worked for 2 years using a different database. I have tried it using Server, instead of Data Source, and UID/User ID instead of UserID with the same result

C#:

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

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

Upvotes: 0

Views: 213

Answers (4)

Sylca
Sylca

Reputation: 2545

make sure that you don't have (somehow - somewhere) two connection strings defined in your project since you were changing database!!!

Upvotes: 1

hagensoft
hagensoft

Reputation: 1497

Try using a space between User and ID or just use User= or UID=

Upvotes: 1

Chris
Chris

Reputation: 627

You don't specify a server, do you? I use following string to connect to mysql hosts:

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

Upvotes: 1

Dave Zych
Dave Zych

Reputation: 21887

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)

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.

Upvotes: 1

Related Questions