efcore icon indicating copy to clipboard operation
efcore copied to clipboard

New app from VS template fails

Open victorhurdugaci opened this issue 12 years ago • 10 comments

  1. Create a new WebApp from template in VS
  2. Switch to CoreCLR
  3. Run
  4. Click Register

Expected: everything works out of the box Actual:

System.Data.SqlClient.SqlException was unhandled by user code
  HResult=-2146232060
  Message=Cannot open database "aspnet5-WebApplication1-fbd89e38-1236-4055-b8fb-0ada0021e17f" requested by the login. The login failed.
Login failed for user 'REDMOND\victorhu'.
  Source=.Net SqlClient Data Provider
  ErrorCode=-2146232060
  _doNotReconnect=false
  Class=11
  LineNumber=65536
  Number=4060
  Procedure=""
  Server=(localdb)\mssqllocaldb
  State=1
  StackTrace:
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
       at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
       at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
       at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, String newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
       at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, String newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
       at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, String newSecurePassword, Boolean redirectedUserInstance)
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, String newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.Open()
       at Microsoft.Data.Entity.Relational.RelationalConnection.Open()
       at Microsoft.Data.Entity.Relational.Query.QueryingEnumerable`1.Enumerator.MoveNext()
       at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
       at Microsoft.Data.Entity.Query.LinqOperatorProvider.<_TrackEntities>d__0`2.MoveNext()
       at Microsoft.Data.Entity.Query.EntityQueryExecutor.EnumerableExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
  InnerException: 

The failure is consistent. It is not a one time only...

EF package: 7.0.0-beta1-11491 (from the release branch)

Code in template:

 public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        private static bool _created = false;

        public ApplicationDbContext()
        {            
            // Create the database and schema if it doesn't exist
            // This is a temporary workaround to create database until Entity Framework database migrations 
            // are supported in ASP.NET 5
            if (!_created)
            {
                Database.AsRelational().ApplyMigrations(); // <<< This is the line that fails

victorhurdugaci avatar Oct 30 '14 17:10 victorhurdugaci

This could be a result of an issue with first time access to LocalDb, is this the first data access you've done on this install of VS? Could you try running the app again and see if it works?

rowanmiller avatar Oct 30 '14 18:10 rowanmiller

I tried to run the app many times. Each time I get the same error.

I think @kirthik has the same problem

victorhurdugaci avatar Oct 30 '14 18:10 victorhurdugaci

@andriysvyryd, fyi

divega avatar Oct 30 '14 18:10 divega

This could be related to Windows Auth not being supported on CoreCLR.

AndriySvyryd avatar Oct 30 '14 19:10 AndriySvyryd

Andriy is investigating for Beta.

rowanmiller avatar Oct 30 '14 21:10 rowanmiller

This seems more like a Tooling issue because this is an internal error that is handled by EF, if you continue past the error it creates the tables and continues running the application perfectly fine.

BrennanConroy avatar Oct 30 '14 21:10 BrennanConroy

I agree with Brennan. Some more info: This also repoes on Desktop CLR "Enable Just My Code" must be checked If you press F10 (Step Over) when the exception is displayed VS crashes.

AndriySvyryd avatar Oct 31 '14 23:10 AndriySvyryd

Thanks @AndriySvyryd for the fix! For some more context on the resolution, here is what he said:

I found the culprit, it’s the temporary SqlClient.

Just My Code allows to break on user-unhandled exceptions (enabled by default), this refers to exceptions that pass through “user code” without being handled.

User code or “My Code” refers to code that is not optimized and has matching pdbs.

We are including the pdbs in the SqlClient package making VS think that’s “My Code”

The fact that this was making VS crash is still concerning. @victorhurdugaci do you think there is some way we can redirect that part to VS?

divega avatar Nov 01 '14 00:11 divega

@mayurid can you please help us identify a VS contact?

victorhurdugaci avatar Nov 03 '14 18:11 victorhurdugaci

Talked to Reshmim and she is working on this.

mayurid avatar Nov 03 '14 18:11 mayurid