数据库连接的方法
<connectionStrings>
<!--<add name="ProwebEntities" connectionString ="Data Source=.;Integrated Security=false;Initial Catalog=Saienyitai;User ID=sa;Password=sa;MultipleActiveResultSets=true" providerName ="System.Data.SqlClient"/>-->
<!--<add name="ProwebEntities" connectionString ="Data Source=.;Integrated Security=true;Initial Catalog=Saienyitai;MultipleActiveResultSets=true" providerName ="System.Data.SqlClient"/>-->
<!--<add name="ProwebEntities" connectionString ="Data Source=.;Integrated Security=false;Initial Catalog=Saienyitai;User ID=sa;Password=sa;MultipleActiveResultSets=true" providerName ="System.Data.SqlClient"/>-->
<!--<add name="ProwebEntities" connectionString ="Data Source=.;Integrated Security=true;Initial Catalog=Saienyitai;MultipleActiveResultSets=true" providerName ="System.Data.SqlClient"/>-->
<add name="ProwebEntities" connectionString="Data Source=|DataDirectory|Saienyitai.sdf" providerName="System.Data.SqlServerCe.4.0"/>
<!--<add name="ProwebEntities" connectionString="Data Source=.;Integrated Security=false;Initial Catalog=Saienyitai;User ID=sa;Password=sa;MultipleActiveResultSets=true" providerName="System.Data.SqlClient"/>-->
<!--<add name="ProwebEntities" connectionString="Data Source=.;Integrated Security=true;Initial Catalog=Saienyitai;MultipleActiveResultSets=true" providerName="System.Data.SqlClient"/>-->
</connectionStrings>
ProwebEntities为上下文类 Saienyitai为数据库名称 User ID为数据库名称;Password为数据库密码; 做项目时做相应的替换!
MultipleActiveResultSets可以使数据库连接复用。这样就不怕数据库的连接资源被耗尽了。