错误只发布后发生:"无法连接到任何指定的MySQL主机的" [英] Error only occurs after publishing: "Unable to connect to any of the specified MySQL hosts."

查看:1483
本文介绍了错误只发布后发生:"无法连接到任何指定的MySQL主机的"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发过程中程序运行正常,但一旦公布,我注意到我的要素不填充正确。我首先想到的是与更新板出了问题,但有人告诉我使用Firebug,这是我看到抛出的错误。

During development the program runs fine, but once published I noticed my elements weren't populating properly. I thought at first it was a problem with the update panels, but someone told me to use Firebug, and this is the error I see being thrown.

还是那句话:
无法连接到任何指定的MySQL主机。

Again: "Unable to connect to any of the specified MySQL hosts."

我的code(这部分是从web.config):

My code(This part is from the web.config):

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

在C#中,我正是如此叫的连接字符串:

In C#, I call the connection string thusly:

    string connstring = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MySQLConnection"].ConnectionString;
    MySqlConnection myConnection = new MySqlConnection(connstring);

为什么这任何输入不工作,或者为什么它工作在发展,而不是一旦公布,将大大AP preciated。

Any input on why this isn't working, or why it works in development and not once published, would be greatly appreciated.

感谢。

编辑:新的信息

哦,我的上帝,这是郁闷了。

Oh my god, this is maddening.

所以,我的计划有第二个web.config文件,我不得不previously把一个连接字符串中,一个不正确的数据。当程序运行,这就是它试图用,这就是为什么它不工作。我这样想着。

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(Obj ect demand, StackCrawlMark&             stackMark, Boolean isPermSet)
    at System.Security.CodeAccessSecurityEngine.Check(Cod eAccessPermission cap,             StackCrawlMark& stackMark)
    at System.Security.CodeAccessPermission.Demand()
    at System.Net.Sockets.Socket.CheckCacheRemote(EndPoin t& 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(MySqlConnecti onStringBuilder settings)
    at MySql.Data.MySqlClient.MySqlPool.GetPooledConnecti on()
    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\WordsOfPow er.aspx.cs:line 39

最后编辑:我更新了我的web.config中使用完全信任

Final I updated my web.config to use full trust.

http://support.winhost.com/KB/a657/changing-the-default-aspnet-trust-level.aspx

推荐答案

这是一个信任问题。

请参阅http://www.marthijnvandenheuvel.com/2011/04/14/fix-net-4-socketpermission-for-mysql-driver-in-medium-trust/

这篇关于错误只发布后发生:&QUOT;无法连接到任何指定的MySQL主机的&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆