微软企业库连接数据库问题,50分~
我用了微软企业库的DBBA创建数据库连接,一下是WEBCONFIG的配置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<dataConfiguration defaultDatabase="LocalSqlServer" />
<appSettings>
<!-- 连接字符串是否加密 -->
<add key="ConStringEncrypt" value="false" />
<!-- 连接字符串,(可以扩展支持不同数据库)如果是加密方式,上面一项要设置为true,如果是明文server=127.0.0.1;database=codematic;uid=sa;pwd=,上面设置为false -->
<add key="ConnectionString" value="server=192.168.1.116;database=shopdata;uid=sa;pwd=1" />
<!--8618B53C32BF8E0B6CD3BDFF59B9F24BE1C6D586A5915C8B6DC69A09ABB2DF60A4026BDE8E76B6FDE2BFCEA3FA8E06CB-->
<add key="ConnectionString2" value="server=192.168.1.116;database=shopdata;uid=sa;pwd=1" />
</appSettings>
<system.web>
<!-- 全局主题 -->
<pages theme="BlueTheme" styleSheetTheme="BlueTheme" />
<httpRuntime executionTimeout="3600" maxRequestLength="1048576" />
<compilation debug="true" />
<customErrors mode="Off" />
<identity impersonate="true" />
<authentication mode="Forms">
<forms name="forums" path="/" loginUrl="Login.aspx" protection="All" timeout="40">
</forms>
</authentication>
</system.web>
</configuration>
测试程序时错误提示
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)
源错误:
行 172: db.AddInParameter(dbCommand, "ConfigID", DbType.Int32,ConfigID);
行 173: WebSite.Model.Config model=null;
行 174: using (IDataReader dataReader = db.ExecuteReader(dbCommand))
行 175: {
行 176: if(dataReader.Read())
CS页面代码
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
WebSite.BLL.Config config = new WebSite.BLL.Config();
WebSite.Model.Config configmode = config.GetModel(1);
Response.Write(configmode.ConfigID.ToString());
}
}
}