Database db = DatabaseFactory.CreateDatabase();
DbCommand dc = db.GetStoredProcCommand("proc", parameters);
dc.ExecuteNonQuery();
int a= (int)db.GetParameterValue(dc, "ReturnValue");
return 0;
利用微软企业库database时候,执行到创建database 的时候,会报Activation error occured while trying to get instance of type Database 错误
这个是由于web.cong配置不正确
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<dataConfiguration defaultDatabase="DBInstance" />
<connectionStrings>
<add name="DBInstance" connectionString="data source=数据库名;Initial Catalog=Online;uid=sa;pwd=sa;"
providerName="System.Data.SqlClient" />
</connectionStrings>
检查自己的web.config 企业库配置是否正确,如果像上面这样去配置,就可以解决实例报错的问题