0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

指定された名前付き接続は、構成内に見つからないか、EntityClient プロバイダーと併用することを意図していないか、または無効です

Posted at

.NET Framework4.0のテストプロジェクトに、テストコードを実装しようとしてエラーが発生

テスト メソッド SampleProject.Tests.UnitTest1.TestMethod1 が例外をスローしました:
System.ArgumentException: 指定された名前付き接続は、構成内に見つからないか、EntityClient プロバイダーと併用することを意図していないか、または無効です。

  スタック トレース: 
EntityConnection.ChangeConnectionString(String newConnectionString)
EntityConnection.ctor(String connectionString)
ObjectContext.CreateEntityConnection(String connectionString)
ObjectContext.ctor(String connectionString, String defaultContainerName)
SampleProject.ctor() 行 34
UnitTest1.TestMethod1() 行 18

テストプロジェクトに対してテスト対象のプロジェクトを参照するだけでなく、データベース接続先の設定を持つ必要があるようだ

Untitled (1).png

App.configを作成して、テスト対象のプロジェクトのweb.configにある接続文字列を記述するとビルドが通った

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<connectionStrings>
		<add name="sampleEntities" connectionString="metadata=res://*/Models.sample.csdl|res://*/Models.sample.ssdl|res://*/Models.sample.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-123HITE\SQLEXPRESS;initial catalog=sample_table;user id=sa;password=pass123;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
	</connectionStrings>
</configuration>

リンクか何かで参照できれば良いのだが、方法は調査中...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?