0

で処理されませんでした。したがって、C#を使用してASP.NET Webフォームアプリケーションを作成しようとしています。私はASPとC#の絶対初心者です)。タイプ 'System.Data.SqlClient.SqlException'の例外はmscorlib.dllで発生しましたが、ユーザコード

https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/membership-and-administration

私は、このWindows 7(64ビット)のマシンにSQL Server 2012のExpressのLocalDBでのVisual Studio 2013を使用しています:私はここにあるチュートリアルを以下ました。しかし、私が学校に通っているときは、Windows 10(64ビット)マシンでVisual Studio 2015(同じSQL Serverバージョン)を使用します。

ここでは、VS2013上にあるこのチュートリアルをコーディングしていて、プログラムをビルドして実行した後で動作していました。それをVS2015に移植してプログラムを実行した後、VS2013で再び実行することはできません。代わりに、私はエラーが発生しました。ここで

は完全なエラーテキストです:ここで

An exception of type 'System.Data.SqlClient.SqlException' occurred in 
mscorlib.dll but was not handled in user code 

Additional information: 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: SQL 
Network Interfaces, error: 50 - Local Database Runtime error occurred. The 
specified LocalDB instance does not exist.) 

はソースエラーコードブロック(それが特異的ライン24で発生)である:ここでは

Line 22:    var roleMgr = new RoleManager<IdentityRole>(roleStore); 
Line 23: 
Line 24:    if (!roleMgr.RoleExists("canEdit")) 
Line 25:     IdRoleResult = roleMgr.Create(new IdentityRole { Name = "canEdit" }); 
Line 26: 

は上の表示スタックトレースですエラーページ:

[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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist. 
)] 
    System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +821 
    System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +332 
    System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38 
    System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +699 
    System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +89 
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +426 
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78 
    System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +191 
    System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154 
    System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21 
    System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90 
    System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +217 
    System.Data.SqlClient.SqlConnection.Open() +96 
    System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c) +36 
    System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +138 
    System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +477 
    System.Data.Entity.SqlServer.<>c__DisplayClass33.<UsingConnection>b__32() +520 
    System.Data.Entity.SqlServer.<>c__DisplayClass1.<Execute>b__0() +34 
    System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +251 
    System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) +196 
    System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act) +276 
    System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act) +545 
    System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript) +151 
    System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) +287 
    System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) +111 
    System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase() +236 
    System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection) +143 
    System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +207 
    System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +42 
    System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) +136 
    System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update() +33 
    System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext) +175 
    System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState) +150 
    System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +444 
    System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +290 
    System.Data.Entity.Internal.<>c__DisplayClassf`1.<CreateInitializationAction>b__e() +165 
    System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +110 
    System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +660 
    System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +31 
    System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +143 
    System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +292 
    System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +123 
    System.Data.Entity.Internal.InternalContext.Initialize() +42 
    System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +39 
    System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +137 
    System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +38 
    System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +99 
    System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken) +197 
    System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(IQueryable`1 source, Expression`1 predicate) +233 
    Microsoft.AspNet.Identity.EntityFramework.RoleStore`3.FindByNameAsync(String roleName) +1120 
    Microsoft.AspNet.Identity.<FindByNameAsync>d__13.MoveNext() +278 
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 
    System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +28 
    Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +123 
    Microsoft.AspNet.Identity.<RoleExistsAsync>d__d.MoveNext() +612 
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 
    System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +28 
    Microsoft.AspNet.Identity.AsyncHelper.RunSync(Func`1 func) +244 
    Microsoft.AspNet.Identity.RoleManagerExtensions.RoleExists(RoleManager`2 manager, String roleName) +241 
    Starlane.Logic.RoleActions.AddUserAndRole() in F:\WEBENGINEERING\Starlane\Starlane\Logic\RoleActions.cs:24 
    Starlane.Global.Application_Start(Object sender, EventArgs e) in F:\WEBENGINEERING\Starlane\Starlane\Global.asax.cs:28 

[HttpException (0x80004005): 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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist. 
)] 
    System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +10063289 
    System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118 
    System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +173 
    System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336 
    System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296 

[HttpException (0x80004005): 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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist. 
)] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10044576 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254 

私がroleMgr varを利用するコード行をコメントアウトすると、 pplicationが実行されますが、ログインシステムをテストしようとすると、同じSqlExceptionエラーが発生します。私はこれが私のWeb.Configファイルで修正できると考えていました。ここで私は、関連するだろうと想像私は(一部のGoogleの調査の後に)見たコードの一部は次のとおりです。

サーバーエクスプローラを使用して
<connectionStrings> 
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-Starlane-20170802095040.mdf;Initial Catalog=aspnet-Starlane-20170802095040;Integrated Security=True" providerName="System.Data.SqlClient"/> 
    <add name="Starlane" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\starlane.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/> 
    </connectionStrings> 

、私はStarlaneデータベースではなく、デフォルトの接続データベースを照会することができます。

とにかく、誰かがこの問題を解決するのに役立つかもしれないように、私は十分な情報を提供したいと思います。この問題の原因となる2015年から2013年にかけてコードや設定が変更されることはありますか?

ありがとうございます。

+0

あなたはSQLの例外とは何の関係もないvsのバージョンと混同しています。 *サーバーエクスプローラを使用して、Starlaneデータベースを照会できますが、デフォルトのConnectionデータベースは照会できません。*データベースを表示できない場合は、接続文字列がどのように機能すると思いますか? Google:**エラー:50 - ローカルデータベースランタイムエラーが発生しました。指定したLocalDBインスタンスが存在しません。** –

+0

ありがとうございました。私は、バージョン切り替えについてあまりにも多く考えると、間違った方向に私を導いた。私は別の投稿が助けになったので、投稿する前にもう少し調べておくべきだった:https://stackoverflow.com/questions/26007913/the-specified-localdb-instance-does-not-exist – pandorachaos

答えて

0

インスタンスが存在するかどうかを確認する必要があります。 cmdプロンプトでsqllocaldb.exeを実行してみてください。

"sqllocaldb i"を使用して、すべてのLocalDBインスタンスを一覧表示します。 "sqllocaldb create instance name"を使用して新しいインスタンスを作成します。 "sqllocaldb start instance name"を使用して開始します。

+0

だから、私が完了したことは見ていたインスタンスとv11.0が停止したので、私はそれを開始しました。また、MSSQLLocalDBインスタンスを作成して起動しました。その後、私のプロジェクトでは、データベースが既に作成されているというエラーが表示されたので、App_Dataフォルダから移動しました(フォルダ内のファイルはあまり変更されていないので削除できました)。出来た!助けてくれてありがとう。 – pandorachaos

関連する問題