質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Entity Framework

Entity Frameworkは、.NET Framework 3.5より追加されたデータアクセス技術。正式名称は「ADO.NET Entity Framework」です。データベースエンジンに依存しておらず、データプロバイダの変更のみで様々なデータベースに対応できます。

SQL Server

SQL Serverはマイクロソフトのリレーショナルデータベース管理システムです。データマイニングや多次元解析など、ビジネスインテリジェンスのための機能が備わっています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

IIS

IIS(Internet Information Services)はマイクロソフト社によって開発されたwebサーバーです。Windows上で動作します。

ASP.NET

ASP.NETは動的なWebサイトやWebアプリケーション、そしてWebサービスを構築出来るようにする為、Microsoftによって開発されたウェブアプリケーション開発フレームワークです。

Q&A

解決済

1回答

4063閲覧

SQL Serverに対してEF6でUpdate-Database実行時にSqlExceptionが発生してしまう

monagano

総合スコア246

Entity Framework

Entity Frameworkは、.NET Framework 3.5より追加されたデータアクセス技術。正式名称は「ADO.NET Entity Framework」です。データベースエンジンに依存しておらず、データプロバイダの変更のみで様々なデータベースに対応できます。

SQL Server

SQL Serverはマイクロソフトのリレーショナルデータベース管理システムです。データマイニングや多次元解析など、ビジネスインテリジェンスのための機能が備わっています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

IIS

IIS(Internet Information Services)はマイクロソフト社によって開発されたwebサーバーです。Windows上で動作します。

ASP.NET

ASP.NETは動的なWebサイトやWebアプリケーション、そしてWebサービスを構築出来るようにする為、Microsoftによって開発されたウェブアプリケーション開発フレームワークです。

0グッド

0クリップ

投稿2017/04/28 02:44

編集2017/04/28 03:17

###前提・実現したいこと
Entity Framework 6を使用したコードファースト・マイグレーションで、
パッケージマネージャコンソールから、SQL Serverに対してUpdate-Databaseを実行時に、
SqlException(SQL Network Interfaces, error: 26)が発生し、作業が失敗してしまいます。

以下、実行したコマンド
PM> Update-Database

以前は問題なくマイグレーションできていた認識ですが、
Windows10更新プログラムの適用&再起動以後、上記現象が発生しました。
エラーメッセージから、接続文字列/SQL Serverの構成に問題があると考えております。ご助言いただけると幸いです。

プロジェクト構成

  • Visual Studio Professional 2017
  • ASP.NET MVC5.2.3
  • .NET Framework 4.6.1
  • EntityFramework 6.1.3
  • ASP.NET Identity 2.2.1
  • IIS10(Expressではありません)
  • SQL Server Express 2014

SQL Serverについては、ローカルDBにWindows認証で接続しております。
Web.config上の接続文字列は以下の通りです。(Web.Config全文は文末に記載)

xml

1<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS2014;Initial Catalog=hogefuga;Integrated Security=True;" providerName="System.Data.SqlClient" />

####確認したこと
サーバエクスプローラから以下を実行
データ接続>接続の追加

  • データソース:Microsoft SQL Server (SqlClient)
  • サーバ名:.\SQLEXPRESS2014
  • 認証:Windows認証
  • データベース名:hogefuga

--->接続成功

SSMSから同様に以下で接続

  • サーバ名:.\SQLEXPRESS2014
  • 認証:Windows認証

--->接続成功

ローカルIISにWebブラウザから接続
ApplicationUserによるログイン
. --->正常に成功
既存データモデルの登録(Insert)
. --->正常に成功

###発生している問題・エラーメッセージ
文字数規制にかかってしまったため、一部省略しております。

ターゲット データベースに適用されている SQL ステートメントを表示するには、'-Verbose' フラグを指定します。 System.Data.SqlClient.SqlException (0x80131904): SQL Server への接続を確立しているときにネットワーク関連またはインスタンス固有のエラーが発生しました。サーバーが見つからないかアクセスできません。インスタンス名が正しいこと、および SQL Server がリモート接続を許可するように構成されていることを確認してください。 (provider: SQL Network Interfaces, error: 26 - 指定されたサーバーまたはインスタンスの位置を特定しているときにエラーが発生しました) 場所 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) 場所 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) 場所 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) (中略) 場所 System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) 場所 System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration) 場所 System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run() 場所 System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 場所 System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 場所 System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) 場所 System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force) 場所 System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0() 場所 System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) ClientConnectionId:00000000-0000-0000-0000-000000000000 Error Number: -1、State: 0、Class: 20 SQL Server への接続を確立しているときにネットワーク関連またはインスタンス固有のエラーが発生しました。サーバーが見つからないかアクセスできません。インスタンス名が正しいこと、および SQL Server がリモート接続を許可するように構成されていることを確認してください。 (provider: SQL Network Interfaces, error: 26 - 指定されたサーバーまたはインスタンスの位置を特定しているときにエラーが発生しました)

###Web.Config全文

xml

1<configuration> 2 <configSections> 3 <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 4 <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 5 </configSections> 6 <connectionStrings> 7 <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS2014;Initial Catalog=jslmember;Integrated Security=True;" providerName="System.Data.SqlClient" /> 8 </connectionStrings> 9 <appSettings> 10 <add key="webpages:Version" value="3.0.0.0" /> 11 <add key="webpages:Enabled" value="false" /> 12 <add key="ClientValidationEnabled" value="true" /> 13 <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 14 </appSettings> 15 <system.web> 16 <authentication mode="None" /> 17 <compilation debug="true" defaultLanguage="c#" targetFramework="4.6.1" /> 18 <httpRuntime targetFramework="4.6.1" /> 19 <httpModules> 20 <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /> 21 </httpModules> 22 <globalization fileEncoding="utf-8" /> 23 </system.web> 24 <system.webServer> 25 <modules> 26 <remove name="FormsAuthentication" /> 27 <remove name="ApplicationInsightsWebTracking" /> 28 <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /> 29 </modules> 30 <handlers> 31 <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 32 <remove name="OPTIONSVerbHandler" /> 33 <remove name="TRACEVerbHandler" /> 34 <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 35 </handlers> 36 <validation validateIntegratedModeConfiguration="false" /> 37 </system.webServer> 38 <runtime> 39 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 40 <dependentAssembly> 41 <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" /> 42 <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 43 </dependentAssembly> 44 <dependentAssembly> 45 <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" /> 46 <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 47 </dependentAssembly> 48 <dependentAssembly> 49 <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" /> 50 <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 51 </dependentAssembly> 52 <dependentAssembly> 53 <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" /> 54 <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 55 </dependentAssembly> 56 <dependentAssembly> 57 <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /> 58 <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 59 </dependentAssembly> 60 <dependentAssembly> 61 <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> 62 <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> 63 </dependentAssembly> 64 <dependentAssembly> 65 <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 66 <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 67 </dependentAssembly> 68 <dependentAssembly> 69 <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 70 <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 71 </dependentAssembly> 72 <dependentAssembly> 73 <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 74 <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 75 </dependentAssembly> 76 <dependentAssembly> 77 <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 78 <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 79 </dependentAssembly> 80 </assemblyBinding> 81 </runtime> 82 <entityFramework> 83 <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 84 <parameters> 85 <parameter value="mssqllocaldb" /> 86 </parameters> 87 </defaultConnectionFactory> 88 <providers> 89 <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 90 </providers> 91 </entityFramework> 92 <system.codedom> 93 <compilers> 94 <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> 95 <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" /> 96 </compilers> 97 </system.codedom> 98</configuration>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2017/04/28 04:02

「以前は問題なくマイグレーションできていた認識ですが、Windows10更新プログラムの適用&再起動以後、上記現象が発生しました」というのは(以前は=IIS Express ではなくローカル IIS、LocalDB ではなく SQL Server 2014 Express)絶対に間違いがないのでしょうか?
monagano

2017/04/28 06:36

はい、その通りです。スタートアッププロジェクトがテストになっていたことが原因でした。お騒がせいたしました。
guest

回答1

0

自己解決

自己解決しました。
いつの間にかスタートアッププロジェクトが変更され、テストプロジェクト(hoge.Tests)がスタートアッププロジェクトに設定されておりました。
プロジェクト本体をスタートアッププロジェクトに設定したところ、問題なく接続が行われました。

お騒がせいたしました。申し訳ありません。

【補足】
Update-Databaseに-Verboseオプションを付けて実行した際に、
Using StartUp project '~.Tests'.が表示されてようやく気づきました...

投稿2017/04/28 03:47

monagano

総合スコア246

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問