Database connection issues(MySQL)

Discussion in 'Databases' started by Typewriter, Feb 29, 2012.

  1. So I posted a problem I was having elsewhere in the site originally, but that was when I thought I was having an issue with update panels.

    Someone recommended that I use Firebug to check it out, and that led to me seeing that I was receiving the following error: "Unable to connect to any of the specified MySQL hosts."

    My first thought was something to do with the MySQL dll, but that loaded up properly in the /bin folder, so I don't think that's it.

    I now have no idea. The program works, and connects, just fine when I run it from Visual Web Developer 2010 Express, but once published it does nothing.

    If anyone has any input I'd really appreciate it.
     
    Last edited by a moderator: Oct 14, 2015
  2. Elshadriel

    Elshadriel Winhost Staff

    Have you tried changing the database connection string as you mentioned in your other post?
     
  3. The only thing I could really think to try would have been adding a port, but in experimenting with that nothing good happened.

    The connection string seems to work fine in production though. That being said, here is what I'm doing:

    Web.Config
    <connectionStrings>
    <add name="MySQLConnection" connectionString="[myServer];[myDatabase];UID= [myID];PWD=[myPassword];"
    providerName="MySql.Data.SqlClient" />
    </connectionStrings>

    C#
    string connstring = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MySQLConnection"].ConnectionString;
    MySqlConnection myConnection = new MySqlConnection(connstring);
     
  4. I meant Development, not production.
     
  5. I think I figured out my problem mostly.

    My web.config on the server is old, and it's not updating when I publish. I'm trying to fix this issue now, but if anyone can tell me how to force a publish I'd appreciate it.
     
  6. Oh my god, this is maddening.

    So my program had a second web.config file, and I had previously put a connection string in that one with incorrect data. When the program ran that's what it was trying to use, and that's why it wasn't working. Or so I thought.

    I found this out, of course, after thinking it was the same file, and simply trying to update it. Finally I removed the connection string from the old file altogether, and what do you know, I now know that it's using the proper connection string.

    Hoo-ray for me, right? Nope.

    I now know that it is using the correct connection string, and yet it is still somehow not working.

    That being said, I added some better troubleshooting in, so now I have this:

    MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> System.Security.SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
    at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
    at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
    at System.Security.CodeAccessPermission.Demand()
    at System.Net.Sockets.Socket.CheckCacheRemote(EndPoint& remoteEP, Boolean isOverwrite)
    at System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state)
    at System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state)
    at MySql.Data.Common.StreamCreator.CreateSocketStream(IPAddress ip, Boolean unix)
    at MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout)
    at MySql.Data.MySqlClient.NativeDriver.Open()
    The action that failed was:
    Demand
    The type of the first permission that failed was:
    System.Net.SocketPermission
    The Zone of the assembly that failed was:
    MyComputer
    at MySql.Data.MySqlClient.NativeDriver.Open()
    at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
    at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
    at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
    at MySql.Data.MySqlClient.MySqlPool.GetConnection()
    at MySql.Data.MySqlClient.MySqlConnection.Open()
    at WordsOfPower.testing.update_words() in C:\Users\AJ\documents\visual studio 2010\Projects\WordsOfPower\WordsOfPower\WordsOfPower.aspx.cs:line 39
     
  7. Elshadriel

    Elshadriel Winhost Staff

    Last edited by a moderator: Oct 14, 2015
  8. I did not realize that was something I changed as part of my application, I thought it was part of the configuration on the MySQL server itself.

    Thank you so very, very much.
     
  9. Glad you got it worked out.
     
  10. weird...

    i happen to have the same problem as he do... the error wont show until i added full trust on config file..

    then, i was surprised to see that my user in mssql is the one used by the application for mysql db... those are completely different config name.

    had to "hardcode" the username part of the connectionstring as a workaround...
    :(
     

Share This Page