1

ASP.NET Core 1.0 Webアプリケーション(Entity Framework Core)からSQL Server 2014または2016に接続しようとしています。私は以下のエラーが発生しています。どのようにそれを解決するためのヒント。ASP.NET Core 1 EF7でSQL Serverに接続できません

Visual Studio 2015 SQL ServerオブジェクトエクスプローラからDBに正常に接続できます。ただし、Webアプリケーションからの接続は失敗します。どちらも私はdotnet ef database updateできません。

私はLOCALDBに接続できます。

"DefaultConnection": "Data Source=server;Initial Catalog=TestDb;Integrated Security=False;User ID=sa;Password=*****;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" 

私が手にエラーがある:

私の接続文字列は次のようになります。私は、SQL Server 2014および2016で同じエラーを取得:

An unhandled exception occurred while processing the request. 

Win32Exception: The network path was not found 
.ctor 

SqlException: 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) 

スタックトレースは次のとおりです。

Win32Exception: The network path was not found 
.ctor 
CreateConnection 
CreatePooledConnection 
CreateObject 
UserCreateRequest 
TryGetConnection 
WaitForPendingOpen 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
GetResult 
MoveNext in AccountController.cs 
       var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false); 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 
MoveNext 
ThrowForNonSuccess 
HandleNonSuccessAndDebuggerNotification 
MoveNext 

EDIT 1

これは同じ問題ではありません、注意してください。なぜ私は得るのですか"Cannot Connect to Server - A network-related or instance-specific error"?

EDIT 2

問題が発生しているこのプロジェクトのタイプは、ASP.NETコアWebアプリケーション(.NET コアです。

私はASP.NETコアWebアプリケーションを作成することで、試してみましたが(.NET Frameworkのプロジェクトとそこには問題はありませんでした。私は接続することができました。 ASP.NET Core Web Application (.NET Core) does not connect to the SQL server and .NET Framework) projects connects

これらのプロジェクトの違いは何ですか?

+0

の可能性のある重複した[なぜ私が「サーバーに接続できない - ネットワーク関連またはインスタンス固有のエラー」を取得しています?](http://stackoverflow.com/questions/18060667/why-am-iネットワークに関連する、またはインスタンス固有のサーバーに接続できません) – Igor

+0

これは重複していないため、同じ問題ではありません。 VS2015 SQL Server Object ExplorerやSerer Management Studioなど、他のクライアントからサーバーに接続できます。しかし、私のASP.NET Core MVC Webアプリケーションは失敗します。 – feradz

+0

接続文字列を最小限に抑えようとしましたか? 'Data Source'、' Initial Catalog'、 'User ID'、' Password'パラメータを使って試してみましょう。 – Brad

答えて

0

この問題は、ASP.NET Core 1にバグがあるようで、少なくともSQL Serverなどの接続文字列をサポートしていないように思われるために発生します。

具体的には、ASP.NETコアを対象とするプロジェクトがある場合に問題が発生します。たとえば、あなたがASP.NETコアWebアプリケーションを作成する場合、問題は(.NET コアプロジェクトを存在しますが、あなたはASP.NETコアWebアプリケーション(.NET Frameworkのを作成した場合は存在しません。この問題を回避するために

enter image description here

一つの方法は、そのようなあなたのproject.jsonファイルを変更することにより、.NET Frameworkのプラットフォーム"net461": {}を標的とすることです。

"frameworks": { 
    "netcoreapp1.0": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "version": "1.0.1", 
      "type": "platform" 
     } 
     }, 
     "imports": [ 
     "dotnet5.6", 
     "portable-net45+win8" 
     ] 
    }, 
    "net461": {} 
    }, 

EDIT

これは、ここで説明するバグ/問題についてのgitのハブへのリンクです。 https://github.com/dotnet/corefx/issues/4586

+0

Githubの関連する問題へのリンクがありますか? –

+0

こんにちはマイク、私はちょうど私の答えをリンクを追加して更新しました。 https://github.com/dotnet/corefx/issues/4586 – feradz

+0

この問題はバグではなく、あなたの状況に当てはまらないようです。自分の投稿で指定した情報から名前付きインスタンスを使用しているようには見えません。 –

2

今日も同様の問題がありました。 SQL Serverへの.Netコア接続文字列は、以前の.Net SQL Server接続文字列とは少し違っているようです。あなたは1 specified here on the MSDN Blog?に似たものを使用してみました:

using (var connection = new SqlConnection("Server=tcp:YourServer,1433;Initial Catalog=YourDatabase;Persist Security Info=True;")) 

(あなたは「リレーショナルデータベース」と「SQL Serverのサブ見出しにページをスクロールダウンしている場合、あなたは例があります。)

をした場合あなたは、文字列にユーザー名とパスワードを使用している、あなたもこれを試みることができる:

"Server=tcp:yourservername,1433;Initial Catalog=yourdbname;User ID=yourusername;Password=yourpassword;" 
0

私は同じissue.Iは多くのウェブサイトを試してみました直面した今日では、最後に、私たちは、サーバのポート番号を指定する必要がありますことを発見接続文字列。

Server = tcp:<ServerName>,<PortName>; Database = <DataBaseName>; User Id = <UserName>; Password = <Password>; 

次のクエリを使用してサーバーポート番号を取得します。

select distinct local_net_address, local_tcp_port from sys.dm_exec_connections where local_net_address is not null 
関連する問題