[EF CTP4]如何指定连接字符串? [英] [EF CTP4] How can I spcify a connection string?

查看:95
本文介绍了[EF CTP4]如何指定连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试运行一个简单的演示来体验如何使用EF CTP4进行开发,最后我遇到了运行时错误"提供程序没有返回ProviderManifestToken字符串",我认为这是由我的sql server引起的计算机 不允许Windows身份验证(可能需要
用户ID和密码),因此我将SqlConnection对象传递给DemoContext(DbContext)的构造函数。

 
public DemoContext(SqlConnection连接)
:< span style ="color:Blue;"> base (connection)
{
}

解决方案

您可以在app.config或此部分的web.config中指定连接字符串  < connectionStrings >


Sql server express DB就像这样:



<


< font face ="Consolas"size ="2"color ="#0000ff">

 



 



add
名称 = " _ MNG_Model "
connectionString = " data
source = .\SQLEXPRESS; Integrated Security = SSPI; Initial Catalog = MyDB
"
providerName = " System.Data.SqlClient " />


或者您可以像这样指定一个本地压缩文件。


<



 



 




add
名称 = " MyDB "
connectionString = " 数据
源= | DataDirectory | MyDB.sdf
"
providerName = " System.Data.SqlServerCe.4.0 " />



I tried to run a simple demo to experiencing how to develop with EF CTP4, finally I got a runtime error "The provider did not return a ProviderManifestToken string", I thought it's caused by the sql server on my computer doesn't allow Windows Authentication(maybe userid and password are required), so I passed a SqlConnection object to DemoContext(DbContext)'s constructor.

public DemoContext(SqlConnection connection)
   : base(connection)
{
}

解决方案

You can specify your connection string in your app.config, or your web.config in this secton <connectionStrings>

Sql server express DB like this:

<

 

 

add name="_MNG_Model" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=MyDB" providerName="System.Data.SqlClient"/>

Or you can specify a local compact file like this.

<

 

 

add name="MyDB" connectionString="Data Source=|DataDirectory|MyDB.sdf" providerName="System.Data.SqlServerCe.4.0"/>


这篇关于[EF CTP4]如何指定连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆