在数据库DB失败= DatabaseFactory.CreateDatabase(); [英] Failing at Database db = DatabaseFactory.CreateDatabase();

查看:144
本文介绍了在数据库DB失败= DatabaseFactory.CreateDatabase();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

故障切​​换左右数据库DB = DatabaseFactory.CreateDatabase(); ,我不知道为什么。我与执行手动声明参数存储过程和她工作就好了。虽然,我没有给出错误或任何走下车的,所以我不知道什么是错。我坚持在每行领导到code休息,而数据库DB = DatabaseFactory.CreateDatabase()之后; 行,它停在那里,我以后告诉IDE继续它将跳过该行和函数结束。

有关记录,我引用固体为好。我已经拆从其他项目我做这个code,所以我可能只是缺少一些愚蠢的。无论如何,这里的code:

 公共类PullDebtor
{
    公共静态数据表ClientNumber(字符串strClientID)
    {        数据集dsDebtor =新的DataSet();
        dsDebtor.Tables.Add(借方);
        的DbCommand的DbCommand = NULL;        尝试
        {            数据库DB = DatabaseFactory.CreateDatabase();            字符串的SqlCommand =sp_PullClientID;
            的DbCommand dbCommand1 = db.GetSqlStringCommand(的SqlCommand);
            dbCommand1.CommandType = CommandType.StoredProcedure;
            db.AddInParameter(dbCommand1,@ClientID,DbType.String,strClientID);            db.ExecuteNonQuery(dbCommand1);            dsDebtor = db.ExecuteDataSet(dbCommand1);
        }
        抓住
        {
            返回dsDebtor.Tables [0];
        }
        最后
        {        }
        返回dsDebtor.Tables [0];    }
}
}


解决方案

你有没有编辑过的.config 部分?你需要像somethig:

 <节名称=dataConfigurationTYPE =Microsoft.P​​ractices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,Microsoft.P​​ractices.EnterpriseLibrary.Data,版本4.1.0.0 =文化=中性公钥= 31bf3856ad364e35/>

和您还需要配置部分指向您已在连接字符串部分中定义的连接字符串:

 < dataConfiguration defaultDatabase =连接字符串/>

Failing over around Database db = DatabaseFactory.CreateDatabase(); and I'm not sure why. I executed the stored proc with manual parameters declared and she worked just fine. Though, I'm not being given an error or anything to go off of, so I'm not sure whats wrong. I stick a break in the code on each line leading up to, and after the Database db = DatabaseFactory.CreateDatabase(); line and it stops there, after I tell the IDE to continue it skips that line and the function ends.

For the record, my references are solid as well. I've cannibalized this code from another project I've done, so I'm likely just missing something silly. Regardless, here's the code:

public class PullDebtor
{
    public static DataTable ClientNumber(string strClientID)
    {

        DataSet dsDebtor = new DataSet();
        dsDebtor.Tables.Add("Debtors");
        DbCommand dbCommand = null;

        try
        {

            Database db = DatabaseFactory.CreateDatabase();

            string sqlCommand = "sp_PullClientID";
            DbCommand dbCommand1 = db.GetSqlStringCommand(sqlCommand);
            dbCommand1.CommandType = CommandType.StoredProcedure;
            db.AddInParameter(dbCommand1, "@ClientID", DbType.String, strClientID);

            db.ExecuteNonQuery(dbCommand1);

            dsDebtor = db.ExecuteDataSet(dbCommand1);
        }
        catch
        {
            return dsDebtor.Tables[0];
        }
        finally
        {

        }
        return dsDebtor.Tables[0];

    }
}
}

解决方案

Have you edited your .config sections? You need somethig like:

<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

And you also need a config section pointing to the connection string you have defined in your connection strings section:

<dataConfiguration defaultDatabase="Connection String" />

这篇关于在数据库DB失败= DatabaseFactory.CreateDatabase();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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