8 Replies - 2160 Views - Last Post: 22 August 2009 - 09:36 PM Rate Topic: -----

#1 PabloMax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-August 09

Can't connect to MYSQL thru C#

Posted 20 August 2009 - 02:49 PM

Just cannot seem to read from MySQL database.

			ConStr = "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=127.0.0.1;DATABASE=db;UID=id;PWD=pwd;OPTION=3;";
			OdbcCon = new System.Data.Odbc.OdbcConnection(ConStr);

			OdbcCon.Open();



returns an error on the final line
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

I know it's probably something stupid, but I'd appreciate any help.

Is This A Good Question/Topic? 0
  • +

Replies To: Can't connect to MYSQL thru C#

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Can't connect to MYSQL thru C#

Posted 20 August 2009 - 02:56 PM

To be honest, when working with MySQL I prefer to use the .Net MySQL Connector rather than OdBc. Once you have the connector here's a snippet showing how to connect to MySQL with C# :)
Was This Post Helpful? 0
  • +
  • -

#3 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Can't connect to MYSQL thru C#

Posted 20 August 2009 - 05:58 PM

The MySQL Connector is indeed the best solution, however you could try changing your connection string to this (not everything is capitalised), I'm not sure if it will help though:
Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=db;UID=id;PWD=pwd;option=3


EDIT: Hold up.. I'm sure that message simply states that the driver (asin, "MySQL ODBC 5.1 Driver") is not installed, and there was no default to fall back on, is the ODBC driver actually installed?

This post has been edited by MageUK: 20 August 2009 - 05:59 PM

Was This Post Helpful? 0
  • +
  • -

#4 PabloMax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-August 09

Re: Can't connect to MYSQL thru C#

Posted 21 August 2009 - 02:37 PM

Yeah, the driver was installed, that was the exact string suggested by my server host. But I just can't connect to the MySQL database from a .aspx page. Oddly, I wrote a .php version of the page and that works fine.

I saw somewhere else some discussion of ODBC User DSN vs. System DSN, could this be the issue? Or does this apply in this case?

Pardon my cluelessness, but what exactly would I have to do to install the .Net connector? I really don't know anything about installing applications on a server.
Was This Post Helpful? 0
  • +
  • -

#5 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Can't connect to MYSQL thru C#

Posted 21 August 2009 - 06:45 PM

Exactly the same as installing any application on your desktop! However, you won't need to do this, you should be able to simply install the connector on your desktop computer, use it in your project, and then upload the built files (including MySQL.Data.dll) onto your server and running them just fine :)
Was This Post Helpful? 0
  • +
  • -

#6 PabloMax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-August 09

Re: Can't connect to MYSQL thru C#

Posted 22 August 2009 - 01:05 PM

OK, my host says they should have the .NET connector installed, but it's still not working. I used the snippet listed above and got a pile of these error messages:

CS0246: The type or namespace name 'MySqlConnection' could not be found (are you missing a using directive or an assembly reference?)

It also didn't like MySqlCommand or MySqlDataReader. I have a "using MySql.Data.MySqlClient" statement so it's got to be something to do with assembly references. This is where I'm really lost. If the connector is installed, what else has to be done? This is really beyond my understanding. Thanks for any help.
Was This Post Helpful? 0
  • +
  • -

#7 mineeric123  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 12-November 08

Re: Can't connect to MYSQL thru C#

Posted 22 August 2009 - 03:31 PM

Hello

I can not see all of your code, but I am just curious, in your code behind do you have a statement like this ?
using MySql.Data.MySqlClient;



Also, did you add a reference to the .net MySQL.Data ?

Let me know

Thanks

Eric Eric
Was This Post Helpful? 0
  • +
  • -

#8 PabloMax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-August 09

Re: Can't connect to MYSQL thru C#

Posted 22 August 2009 - 07:40 PM

Eric, I do have a "using MySql.Date.MySqlClient" statement.

The other part is what I'm unclear about. I don't understand how to add a reference to the .net MySql.Data. I did not install the connector, it was supposedly already installed by the server host company. I am not using Virtual Studio, just trying to edit a pre-existing file to make it work with the database. So how do I add this reference?

I appreciate the input!
Was This Post Helpful? 0
  • +
  • -

#9 mineeric123  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 12-November 08

Re: Can't connect to MYSQL thru C#

Posted 22 August 2009 - 09:36 PM

View PostPabloMax, on 22 Aug, 2009 - 06:40 PM, said:

Eric, I do have a "using MySql.Date.MySqlClient" statement.

The other part is what I'm unclear about. I don't understand how to add a reference to the .net MySql.Data. I did not install the connector, it was supposedly already installed by the server host company. I am not using Virtual Studio, just trying to edit a pre-existing file to make it work with the database. So how do I add this reference?

I appreciate the input!



Can you post the code you are using. I think it would help me figure out how to help you. How are you editing the file?

Normally in Visual Studio or any of the express editions you can just right click the project and select add reference, the browse until you find it.

If you can get at the web config file you could try adding this. I will caution you I have never done this and I am not postive this will work.
   <add assembly="MySql.Data, Version=5.2.6.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>



Also before I sent you the using statement there was a typo in it.

using MySql.Data.MySqlClient;



not
using MySql.Date.MySqlClient;





Regards,

Eric
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1