IIS VB.Net Site crashes on startup trying to use Linq Data Context

0

I inherited a VB.net App running on IIS.

Global.ASAX contains the following:

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    Dim context As New BusLinqDataContext()
    Dim log As New SessionLog()
    log.SessionStart = DateTime.Now
    log.InitialUsername = User.Identity.Name
    context.SessionLogs.InsertOnSubmit(log)
    context.SubmitChanges() <----------------------- This is line 29

    Session.Add("SessionLogId", log.Id)
    Session.Add("SessionUsername", User.Identity.Name)
End Sub

On startup, I get the following error:

Server Error in '/WebApp' Application.

The system cannot find the file specified

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified

Source Error: 


Line 27:    log.InitialUsername = User.Identity.Name
Line 28:    context.SessionLogs.InsertOnSubmit(log)
Line 29:    context.SubmitChanges() <-------------------- ERROR HERE
Line 30:    
Line 31:    Session.Add("SessionLogId", log.Id)

Source File: C:\Websites\www.nationalbus.com\WebApp\global.asax    Line: 29 

Stack Trace: 


[Win32Exception (0x80004005): The system cannot find the file specified]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +6675286
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +688
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +6701832
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +219
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +6703968
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +6704427
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) +610
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +1049
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +74
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) +6706995
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) +78
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +2192
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1012
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6711619
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +152
   System.Data.SqlClient.SqlConnection.Open() +229
   System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) +952
   ASP.global_asax.Session_Start(Object sender, EventArgs e) in C:\Websites\www.nationalbus.com\WebApp\global.asax:29
   System.Web.SessionState.SessionStateModule.CompleteAcquireState() +409
   System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +1269
   System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +12600474
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

If I comment out the Global.ASAX Session_Start(), the application will start, but then crashes later trying to reference the BusLinqDataContext() or anything to do with Session.Add() or other Session variables.

There are other crashes, but they all seem to take place on or near references to the Session variables. Probably because I have Session_Start() commented out in GLOBAL.ASAX.

I had to completely rebuild the app from the IIS web server and SQL Server from the ground up (original system crashed).

I have converted the WebApp folder that contains this part of the system to "IIS Application". And I have (through trial and error) enabled Forms Authentication and Anonymous Authentication. The application uses the built in .NET User Login functionality to manage users and passwords.

I am not a VB.Net developer, so I have limited experience with this stuff.

Does anyone have any ideas? Right now, I suspect something wrong with the line Dim context as New BusLinqDataContext(), but I really do not know. It says "The system cannot find the specified file."

And I suspect the Authentication mode because of the "User.Identity.Name" reference near to the app error line. I suspect "User.Identity.Name" may be NULL - possibly because of an invalid IIS authentication configuration?

Edit

Here are my web.config connection strings:

  <connectionStrings>
    <remove name="LocalSqlServer" />
    <add name="LocalSqlServer" connectionString="Data Source=SATURN\PANDORA;Initial Catalog=tisDatabase;User ID=user;PWD=password;" providerName="System.Data.SqlClient" />
    <remove name="thisConnectionString" />
    <add name="thisConnectionString" connectionString="Data Source=SATURN\PANDORA;Initial Catalog=thisDatabase;User ID=user;PWD=password;" providerName="System.Data.SqlClient" />
    <remove name="thisConnectionString2" />
    <add name="thisConnectionString2" connectionString="Data Source=SATURN\PANDORA;Initial Catalog=thisDatabase;User ID=user;PWD=password;" providerName="System.Data.SqlClient" />
  </connectionStrings>

While it says at the top of the stack trace that it is having trouble connecting to the database, other parts of the app use the database and connect successfully using these connection strings. Again, it seems to be limited to the BusLinqDataConext() related stuff, and the User.Identity.Name as best as I can tell.

User names and passwords changed to protect the innocent.

Edit 2

Also, I have to comment out this section of web.config, or I get a "500 Internal Server Error" with no further details. With this section commented out, the app runs fine, including database interaction - except when it comes to Session() variables.

  <configSections>
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
          <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
  </configSections>
asp.net
vb.net
linq
iis
global-asax
asked on Stack Overflow May 4, 2016 by Kirby L. Wallace • edited Jul 7, 2018 by halfer

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0