.NET Stack Trace Failing to Connect to MySQL
-
I have a C# .NET application that works fine with one database and fails when connecting to a copy of it hosted somewhere else. I'm a little confused by why it is failing as when I attempt to connect manually it gives me no issues and there is no DNS entry for either database server. The one that works is on the LAN, the one that fails is on the WAN, but not clear how that would create this issue.
Here is the stack track:
Stack Trace: [SocketException (0x2af9): No such host is known] System.Net.Dns.GetAddrInfo(String name) +471 System.Net.Dns.InternalGetHostByAddress(IPAddress address, Boolean includeIPv6, Boolean throwOnFailure) +125 System.Net.Dns.GetHostEntry(String hostNameOrAddress) +5414699 MySql.Data.Common.StreamCreator.GetStream(UInt32 timeOut) +338 MySql.Data.MySqlClient.NativeDriver.Open() +303 [MySqlException: Unable to connect to any of the specified MySQL hosts] MySql.Data.MySqlClient.NativeDriver.Open() +355 MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() +147 MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() +54 MySql.Data.MySqlClient.MySqlPool.GetConnection() +52 MySql.Data.MySqlClient.MySqlConnection.Open() +227 DataAccess.GetPageSecurityInfo() in c:\Inetpub\wwwroot\ManagementConsole\App_Code\DataAccess.cs:1358 ASP.global_asax.Application_Start(Object sender, EventArgs e) in c:\Inetpub\wwwroot\ManagementConsole\Global.asax:18
-
Okay, a bit crazy but I created a hosts file entry on the application server for the database server and it moved forward! No idea why that works, but the error seemed to indicate that that would be the case so, whatever. Now I have a new error, of course:
Source Error: Line 97: Dictionary<string, int> pageSecurity = (Dictionary<string, int>)Application["pageSecurity"]; Line 98: Line 99: if (pageSecurity.ContainsKey(appRelativeVirtualPath)) Line 100: { Line 101: Permission permissionRequired
-
And here is the associated stack trace to go with it:
Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] Main.IsAccessAllowed(String appRelativeVirtualPath) in c:\Inetpub\wwwroot\ManagementConsole\Main.master.cs:99 Main.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\ManagementConsole\Main.master.cs:24 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Control.LoadRecursive() +141 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
-
Sadly not as obvious of a problem as the first portion was.
-
Pinging @andyw as he is our resident .NET expert (and the author of the code in question.)
-
FYI: If I make no change except to direct the request to the "old" database, this error goes away and all works fine. The moment that I point the application server to the "new" database (same platform, same version, full copy) I get the error.
-
Try restarting the app or recycling the applicaton pool after pointing to the new database. There may be some startup code that has to run.
Somewhere the Application object has to be loaded with an object with a key of "pageSecurity", and startup is the most likely place for that to happen. Since it's not happening, the code in Main.master.cs (the code file for the main ASP.NET master page, which is sort of like a layout template) is blowing up.
-
@AndyW said:
Try restarting the app or recycling the applicaton pool after pointing to the new database. There may be some startup code that has to run.
Seems unlikely since under circumstances where the existing database changes IP addresses it just needs to be repointed and not recycled. And when I point back, it just works right away too. I'll try that though.
-
@AndyW said:
Somewhere the Application object has to be loaded with an object with a key of "pageSecurity", and startup is the most likely place for that to happen. Since it's not happening, the code in Main.master.cs (the code file for the main ASP.NET master page, which is sort of like a layout template) is blowing up.
Thanks, will test that tomorrow.
-
I see what you mean. And also, if you're making the change in the web.config, that should trigger an application restart anyway.
Something is preventing the pageSecurity object from being set. You could do a global text search for "pageSecurity" and find the code that sets it. That may be where the failure is happening.
Normally I would expect this to be caused by a missing security-related table, like Roles or something. But you said it was a full copy. You might want to double check.