1
votes

I'm writing a C# program in Visual Studio 2010 to be an Excel macro. I'm attempting to connect the program to a MySql database. When I try to build, I get errors like the following:

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

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

I have already downloaded the .NET MySql connector and added a Visual Studio reference to MySql.Data.dll, and I have "using MySql.Data.MySqlClient;" at the top of my program. These two things seem to be the hangups for everyone else on the internet that sees these errors.

Why else could I be getting these errors, and how can I resolve them?

EDIT: Also, when I type the using statement, the IDE does not autocomplete MySql for me; it doesn't seem to know what/where it is.

Apart from the using statement, shown above, I get errors when trying to use MySqlConnection, e.g. as below

public Dictionary <string, MySqlConnection> m_envToCon;

1
can you show the code where you're using this? (where the errors are) - ps2goat
Are you sure to have the using statement in the same file.cs where you have the declaration of the dictionary? By the way, that line raises a lot of question by itself. Why do you need to keep a dictionary with MySqlConnection as values? - Steve
The errors anytime I reference the MySql types. I've added another sample line above. - Nate
Yes, the "using" and the Dictionary are in the same file. - Nate
And, of course, the project that contains the file has the reference, right? - Steve

1 Answers

0
votes

I've encountered this error and had to explicitly remove the connection by name before devenv could build.

  <remove name="connectionName" />

Add the above statement before the connection add tag

  <connectionStrings>
    <remove name="MySql" />
    <add name="MySql" connectionString="..." />
    <remove name="MySqlConnection" />
    <add name="MySqlConnection" connectionString="..." />
  </connectionStrings>