Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法连接到任何指定的MySQL主机,以前的代码正常工作_C#_Mysql_Asp.net_Web Config - Fatal编程技术网

C# 无法连接到任何指定的MySQL主机,以前的代码正常工作

C# 无法连接到任何指定的MySQL主机,以前的代码正常工作,c#,mysql,asp.net,web-config,C#,Mysql,Asp.net,Web Config,摘要: MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts. ---> System.Security.SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture

摘要:

MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the     specified MySQL hosts. ---> System.Security.SecurityException: Request for the     permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0,     Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
 at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
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 first permission that failed was: 
The demand was for: 
The granted set of the failing assembly was: 
The assembly or AppDomain that failed was: MySql.Data, Version=6.2.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d 
The method that caused the failure was: System.IO.Stream CreateSocketStream(System.Net.IPAddress, Boolean) 
The Zone of the assembly that failed was: Intranet The Url of the assembly that failed was: file://PROAPPSRV/inetpub/wwwroot/MyChiller/bin/MySql.Data.DLL -    
-- End of inner exception stack trace --- 
at MySql.Data.MySqlClient.NativeDriver.Open() at     MySql.Data.MySqlClient.Driver.Open() at     MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at     MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() 
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 TCCVC_Login.ValidateUser(Object sender, EventArgs e)
    using (MySqlConnection conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["newrst110ConnectionString"].ConnectionString))
    {

        using (MySqlCommand cmd = conn.CreateCommand())
        {
            try
            {
                cmd.Connection = conn;
                conn.Open();
                cmd.CommandText = @"SELECT custpass AS hash, (lastlogin IS NOT NULL) AS firstLogin FROM rts110.mychiller_users
                                        WHERE custusername = @user";
                cmd.Parameters.AddWithValue("@user", Login1.UserName);
                MySqlDataReader reader = cmd.ExecuteReader();

                DataTable returnTable = new DataTable();
                returnTable.Load(reader);
                reader.Close();

                // UPDATE LAST LOGIN DATE
                cmd.CommandText = @"UPDATE mychiller_users
                                        SET lastLogin = CURDATE()
                                        WHERE custusername = @userName";
                cmd.Parameters.AddWithValue("@userName", Login1.UserName);
                cmd.ExecuteNonQuery();

                cmd.Dispose();

                // . . . 
                // Additional code down here that handles the return and closes the connection.
<add name="newrst110ConnectionString" connectionString="Datasource=70.103.118.100;Database=rts110;uid=####;pwd=####;" providerName="MySql.Data.MySqlClient"/>
Server Error in '/' Application.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +54
System.Net.Sockets.Socket.CheckCacheRemote(EndPoint& remoteEP, Boolean isOverwrite) +270
System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state) +175
System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state) +179
MySql.Data.Common.StreamCreator.CreateSocketStream(IPAddress ip, Boolean unix) +239
MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout) +650
MySql.Data.MySqlClient.NativeDriver.Open() +366
我在尝试通过ASP.NET web应用程序连接MySQL数据库时遇到“无法连接到任何指定的MySQL主机,以前的工作代码”错误。完整错误如下所示

奇怪的是,我只是在一个临时的新网站项目中开发了这个应用程序,在那里一切正常。然而,当我将它应用到我试图实现它的网站的脱机版本时,就会出现这个错误。有趣的是,我实际上使用的是一个连接字符串,它已经在网站中正确设置和运行。所以我不明白为什么我的代码在其他地方运行,而连接字符串在其他地方运行,但是当我尝试将它们一起使用时,会出现“无法连接”错误

我所尝试的:

MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the     specified MySQL hosts. ---> System.Security.SecurityException: Request for the     permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0,     Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
 at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
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 first permission that failed was: 
The demand was for: 
The granted set of the failing assembly was: 
The assembly or AppDomain that failed was: MySql.Data, Version=6.2.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d 
The method that caused the failure was: System.IO.Stream CreateSocketStream(System.Net.IPAddress, Boolean) 
The Zone of the assembly that failed was: Intranet The Url of the assembly that failed was: file://PROAPPSRV/inetpub/wwwroot/MyChiller/bin/MySql.Data.DLL -    
-- End of inner exception stack trace --- 
at MySql.Data.MySqlClient.NativeDriver.Open() at     MySql.Data.MySqlClient.Driver.Open() at     MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at     MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() 
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 TCCVC_Login.ValidateUser(Object sender, EventArgs e)
    using (MySqlConnection conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["newrst110ConnectionString"].ConnectionString))
    {

        using (MySqlCommand cmd = conn.CreateCommand())
        {
            try
            {
                cmd.Connection = conn;
                conn.Open();
                cmd.CommandText = @"SELECT custpass AS hash, (lastlogin IS NOT NULL) AS firstLogin FROM rts110.mychiller_users
                                        WHERE custusername = @user";
                cmd.Parameters.AddWithValue("@user", Login1.UserName);
                MySqlDataReader reader = cmd.ExecuteReader();

                DataTable returnTable = new DataTable();
                returnTable.Load(reader);
                reader.Close();

                // UPDATE LAST LOGIN DATE
                cmd.CommandText = @"UPDATE mychiller_users
                                        SET lastLogin = CURDATE()
                                        WHERE custusername = @userName";
                cmd.Parameters.AddWithValue("@userName", Login1.UserName);
                cmd.ExecuteNonQuery();

                cmd.Dispose();

                // . . . 
                // Additional code down here that handles the return and closes the connection.
<add name="newrst110ConnectionString" connectionString="Datasource=70.103.118.100;Database=rts110;uid=####;pwd=####;" providerName="MySql.Data.MySqlClient"/>
Server Error in '/' Application.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +54
System.Net.Sockets.Socket.CheckCacheRemote(EndPoint& remoteEP, Boolean isOverwrite) +270
System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state) +175
System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state) +179
MySql.Data.Common.StreamCreator.CreateSocketStream(IPAddress ip, Boolean unix) +239
MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout) +650
MySql.Data.MySqlClient.NativeDriver.Open() +366
第一件事显然是检查连接字符串的格式是否正确。我确实仔细检查了这一点,但正如我所说的,连接字符串已经(并且仍然)与站点上的其他页面一起工作

我还看到一些关于这个错误的帖子,建议我在web.config文件中包含这个标记。然而,这并没有解决我的问题

我还验证了我的MySQL数据库是否正常运行。如上所述,我可以获得用于处理页面其他方面的连接字符串

代码片段:

MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the     specified MySQL hosts. ---> System.Security.SecurityException: Request for the     permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0,     Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
 at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
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 first permission that failed was: 
The demand was for: 
The granted set of the failing assembly was: 
The assembly or AppDomain that failed was: MySql.Data, Version=6.2.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d 
The method that caused the failure was: System.IO.Stream CreateSocketStream(System.Net.IPAddress, Boolean) 
The Zone of the assembly that failed was: Intranet The Url of the assembly that failed was: file://PROAPPSRV/inetpub/wwwroot/MyChiller/bin/MySql.Data.DLL -    
-- End of inner exception stack trace --- 
at MySql.Data.MySqlClient.NativeDriver.Open() at     MySql.Data.MySqlClient.Driver.Open() at     MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at     MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() 
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 TCCVC_Login.ValidateUser(Object sender, EventArgs e)
    using (MySqlConnection conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["newrst110ConnectionString"].ConnectionString))
    {

        using (MySqlCommand cmd = conn.CreateCommand())
        {
            try
            {
                cmd.Connection = conn;
                conn.Open();
                cmd.CommandText = @"SELECT custpass AS hash, (lastlogin IS NOT NULL) AS firstLogin FROM rts110.mychiller_users
                                        WHERE custusername = @user";
                cmd.Parameters.AddWithValue("@user", Login1.UserName);
                MySqlDataReader reader = cmd.ExecuteReader();

                DataTable returnTable = new DataTable();
                returnTable.Load(reader);
                reader.Close();

                // UPDATE LAST LOGIN DATE
                cmd.CommandText = @"UPDATE mychiller_users
                                        SET lastLogin = CURDATE()
                                        WHERE custusername = @userName";
                cmd.Parameters.AddWithValue("@userName", Login1.UserName);
                cmd.ExecuteNonQuery();

                cmd.Dispose();

                // . . . 
                // Additional code down here that handles the return and closes the connection.
<add name="newrst110ConnectionString" connectionString="Datasource=70.103.118.100;Database=rts110;uid=####;pwd=####;" providerName="MySql.Data.MySqlClient"/>
Server Error in '/' Application.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +54
System.Net.Sockets.Socket.CheckCacheRemote(EndPoint& remoteEP, Boolean isOverwrite) +270
System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state) +175
System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state) +179
MySql.Data.Common.StreamCreator.CreateSocketStream(IPAddress ip, Boolean unix) +239
MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout) +650
MySql.Data.MySqlClient.NativeDriver.Open() +366
完全错误:

MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the     specified MySQL hosts. ---> System.Security.SecurityException: Request for the     permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0,     Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
 at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
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 first permission that failed was: 
The demand was for: 
The granted set of the failing assembly was: 
The assembly or AppDomain that failed was: MySql.Data, Version=6.2.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d 
The method that caused the failure was: System.IO.Stream CreateSocketStream(System.Net.IPAddress, Boolean) 
The Zone of the assembly that failed was: Intranet The Url of the assembly that failed was: file://PROAPPSRV/inetpub/wwwroot/MyChiller/bin/MySql.Data.DLL -    
-- End of inner exception stack trace --- 
at MySql.Data.MySqlClient.NativeDriver.Open() at     MySql.Data.MySqlClient.Driver.Open() at     MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at     MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() 
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 TCCVC_Login.ValidateUser(Object sender, EventArgs e)
    using (MySqlConnection conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["newrst110ConnectionString"].ConnectionString))
    {

        using (MySqlCommand cmd = conn.CreateCommand())
        {
            try
            {
                cmd.Connection = conn;
                conn.Open();
                cmd.CommandText = @"SELECT custpass AS hash, (lastlogin IS NOT NULL) AS firstLogin FROM rts110.mychiller_users
                                        WHERE custusername = @user";
                cmd.Parameters.AddWithValue("@user", Login1.UserName);
                MySqlDataReader reader = cmd.ExecuteReader();

                DataTable returnTable = new DataTable();
                returnTable.Load(reader);
                reader.Close();

                // UPDATE LAST LOGIN DATE
                cmd.CommandText = @"UPDATE mychiller_users
                                        SET lastLogin = CURDATE()
                                        WHERE custusername = @userName";
                cmd.Parameters.AddWithValue("@userName", Login1.UserName);
                cmd.ExecuteNonQuery();

                cmd.Dispose();

                // . . . 
                // Additional code down here that handles the return and closes the connection.
<add name="newrst110ConnectionString" connectionString="Datasource=70.103.118.100;Database=rts110;uid=####;pwd=####;" providerName="MySql.Data.MySqlClient"/>
Server Error in '/' Application.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +54
System.Net.Sockets.Socket.CheckCacheRemote(EndPoint& remoteEP, Boolean isOverwrite) +270
System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state) +175
System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state) +179
MySql.Data.Common.StreamCreator.CreateSocketStream(IPAddress ip, Boolean unix) +239
MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout) +650
MySql.Data.MySqlClient.NativeDriver.Open() +366
C#MySQL连接器:

MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the     specified MySQL hosts. ---> System.Security.SecurityException: Request for the     permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0,     Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
 at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
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 first permission that failed was: 
The demand was for: 
The granted set of the failing assembly was: 
The assembly or AppDomain that failed was: MySql.Data, Version=6.2.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d 
The method that caused the failure was: System.IO.Stream CreateSocketStream(System.Net.IPAddress, Boolean) 
The Zone of the assembly that failed was: Intranet The Url of the assembly that failed was: file://PROAPPSRV/inetpub/wwwroot/MyChiller/bin/MySql.Data.DLL -    
-- End of inner exception stack trace --- 
at MySql.Data.MySqlClient.NativeDriver.Open() at     MySql.Data.MySqlClient.Driver.Open() at     MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at     MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() 
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 TCCVC_Login.ValidateUser(Object sender, EventArgs e)
    using (MySqlConnection conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["newrst110ConnectionString"].ConnectionString))
    {

        using (MySqlCommand cmd = conn.CreateCommand())
        {
            try
            {
                cmd.Connection = conn;
                conn.Open();
                cmd.CommandText = @"SELECT custpass AS hash, (lastlogin IS NOT NULL) AS firstLogin FROM rts110.mychiller_users
                                        WHERE custusername = @user";
                cmd.Parameters.AddWithValue("@user", Login1.UserName);
                MySqlDataReader reader = cmd.ExecuteReader();

                DataTable returnTable = new DataTable();
                returnTable.Load(reader);
                reader.Close();

                // UPDATE LAST LOGIN DATE
                cmd.CommandText = @"UPDATE mychiller_users
                                        SET lastLogin = CURDATE()
                                        WHERE custusername = @userName";
                cmd.Parameters.AddWithValue("@userName", Login1.UserName);
                cmd.ExecuteNonQuery();

                cmd.Dispose();

                // . . . 
                // Additional code down here that handles the return and closes the connection.
<add name="newrst110ConnectionString" connectionString="Datasource=70.103.118.100;Database=rts110;uid=####;pwd=####;" providerName="MySql.Data.MySqlClient"/>
Server Error in '/' Application.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +54
System.Net.Sockets.Socket.CheckCacheRemote(EndPoint& remoteEP, Boolean isOverwrite) +270
System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state) +175
System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state) +179
MySql.Data.Common.StreamCreator.CreateSocketStream(IPAddress ip, Boolean unix) +239
MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout) +650
MySql.Data.MySqlClient.NativeDriver.Open() +366
连接字符串:

MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the     specified MySQL hosts. ---> System.Security.SecurityException: Request for the     permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0,     Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
 at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
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 first permission that failed was: 
The demand was for: 
The granted set of the failing assembly was: 
The assembly or AppDomain that failed was: MySql.Data, Version=6.2.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d 
The method that caused the failure was: System.IO.Stream CreateSocketStream(System.Net.IPAddress, Boolean) 
The Zone of the assembly that failed was: Intranet The Url of the assembly that failed was: file://PROAPPSRV/inetpub/wwwroot/MyChiller/bin/MySql.Data.DLL -    
-- End of inner exception stack trace --- 
at MySql.Data.MySqlClient.NativeDriver.Open() at     MySql.Data.MySqlClient.Driver.Open() at     MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at     MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() 
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 TCCVC_Login.ValidateUser(Object sender, EventArgs e)
    using (MySqlConnection conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["newrst110ConnectionString"].ConnectionString))
    {

        using (MySqlCommand cmd = conn.CreateCommand())
        {
            try
            {
                cmd.Connection = conn;
                conn.Open();
                cmd.CommandText = @"SELECT custpass AS hash, (lastlogin IS NOT NULL) AS firstLogin FROM rts110.mychiller_users
                                        WHERE custusername = @user";
                cmd.Parameters.AddWithValue("@user", Login1.UserName);
                MySqlDataReader reader = cmd.ExecuteReader();

                DataTable returnTable = new DataTable();
                returnTable.Load(reader);
                reader.Close();

                // UPDATE LAST LOGIN DATE
                cmd.CommandText = @"UPDATE mychiller_users
                                        SET lastLogin = CURDATE()
                                        WHERE custusername = @userName";
                cmd.Parameters.AddWithValue("@userName", Login1.UserName);
                cmd.ExecuteNonQuery();

                cmd.Dispose();

                // . . . 
                // Additional code down here that handles the return and closes the connection.
<add name="newrst110ConnectionString" connectionString="Datasource=70.103.118.100;Database=rts110;uid=####;pwd=####;" providerName="MySql.Data.MySqlClient"/>
Server Error in '/' Application.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +54
System.Net.Sockets.Socket.CheckCacheRemote(EndPoint& remoteEP, Boolean isOverwrite) +270
System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state) +175
System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state) +179
MySql.Data.Common.StreamCreator.CreateSocketStream(IPAddress ip, Boolean unix) +239
MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout) +650
MySql.Data.MySqlClient.NativeDriver.Open() +366
应用程序错误:

MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the     specified MySQL hosts. ---> System.Security.SecurityException: Request for the     permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0,     Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
 at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
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 first permission that failed was: 
The demand was for: 
The granted set of the failing assembly was: 
The assembly or AppDomain that failed was: MySql.Data, Version=6.2.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d 
The method that caused the failure was: System.IO.Stream CreateSocketStream(System.Net.IPAddress, Boolean) 
The Zone of the assembly that failed was: Intranet The Url of the assembly that failed was: file://PROAPPSRV/inetpub/wwwroot/MyChiller/bin/MySql.Data.DLL -    
-- End of inner exception stack trace --- 
at MySql.Data.MySqlClient.NativeDriver.Open() at     MySql.Data.MySqlClient.Driver.Open() at     MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at     MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() 
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 TCCVC_Login.ValidateUser(Object sender, EventArgs e)
    using (MySqlConnection conn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["newrst110ConnectionString"].ConnectionString))
    {

        using (MySqlCommand cmd = conn.CreateCommand())
        {
            try
            {
                cmd.Connection = conn;
                conn.Open();
                cmd.CommandText = @"SELECT custpass AS hash, (lastlogin IS NOT NULL) AS firstLogin FROM rts110.mychiller_users
                                        WHERE custusername = @user";
                cmd.Parameters.AddWithValue("@user", Login1.UserName);
                MySqlDataReader reader = cmd.ExecuteReader();

                DataTable returnTable = new DataTable();
                returnTable.Load(reader);
                reader.Close();

                // UPDATE LAST LOGIN DATE
                cmd.CommandText = @"UPDATE mychiller_users
                                        SET lastLogin = CURDATE()
                                        WHERE custusername = @userName";
                cmd.Parameters.AddWithValue("@userName", Login1.UserName);
                cmd.ExecuteNonQuery();

                cmd.Dispose();

                // . . . 
                // Additional code down here that handles the return and closes the connection.
<add name="newrst110ConnectionString" connectionString="Datasource=70.103.118.100;Database=rts110;uid=####;pwd=####;" providerName="MySql.Data.MySqlClient"/>
Server Error in '/' Application.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +54
System.Net.Sockets.Socket.CheckCacheRemote(EndPoint& remoteEP, Boolean isOverwrite) +270
System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state) +175
System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state) +179
MySql.Data.Common.StreamCreator.CreateSocketStream(IPAddress ip, Boolean unix) +239
MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout) +650
MySql.Data.MySqlClient.NativeDriver.Open() +366
基于我的谷歌搜索,这再次指向Web.Config文件中的标签,我已经包含在其中。也许我把这个写错了


我想知道它是否也可能与我拥有的两个Web.config文件有关(其中一个位于包含成员页的子文件夹中,用于限制未经验证的会话的访问)。我尝试在两者中添加,但没有发现任何差异。

能否附加一个版本的connectionstring?您的配置文件似乎存在配置错误。

能否附加一个版本的connectionstring?您的配置文件似乎存在配置错误。

在进一步研究应用程序错误后,我发现了以下简化连接字符串:


看了这个问题的答案后,我将解决方案移动到本地驱动器,因为我是从服务器文件夹运行它的。这样做解决了问题,现在一切都正常了。

在进一步研究了我使用简化连接字符串时遇到的应用程序错误后,我偶然发现了以下内容:


看了这个问题的答案后,我将解决方案移动到本地驱动器,因为我是从服务器文件夹运行它的。这样做解决了问题,现在一切都很好。

我编辑了我的问题以添加连接字符串,但正如我所说,该连接字符串成功地用于同一网站的其他方面。我编辑了我的问题以添加连接字符串,但正如我所说,该连接字符串成功地与同一网站的其他方面协同工作。