从firebird数据库中检索数据1.5

时间:2013-10-04 16:51:46

标签: c# asp.net .net firebird nullreferenceexception

我有一个来自firebird 1.5的数据库,扩展名为.CDB

我需要从这个数据库中检索数据(SELECT)。我已设法打开与DB的连接,这是使用的连接字符串:

<add name="FirebirdConnectionString" 
connectionString="User=SYSDBA;Password=masterkey;Database=localhost:C:\temp\BD\ECLECTIC.CDB;
DataSource=localhost;Port=3051;Dialect=3;Charset=NONE;Role=;Connection lifetime=15;              Pooling=false; MinPoolSize=0;MaxPoolSize=50;          
Packet Size=8192; ServerType=1;" 
providerName="FirebirdSql.Data.FirebirdClient"/>

这是我的DatabaseConnection.cs类

private readonly String _connString = ConfigurationManager.ConnectionStrings["FirebirdConnectionString"].ToString();

public void Dispose()
{
    GC.SuppressFinalize(this);
    GC.Collect();
}

public FbConnection OpenConn()
{
    FbConnection conn = new FbConnection(_connString);
    if(conn.State != System.Data.ConnectionState.Open)
        conn.Open();
    return conn;
}

public FbConnection CloseConn(FbConnection conn)
{
    if(conn.State != System.Data.ConnectionState.Closed)
        conn.Close();
    return conn;
}

public FbCommand CreateCommand(String query)
{
    var conn1 = OpenConn();
    var commandQuery = new FbCommand(query, conn1);
    return commandQuery;
}

这是我尝试检索数据的地方:

var dbConnection = new DbConnection();
var conn = dbConnection.OpenConn();

var cmd = new FbCommand();
cmd.CommandText = "SELECT COD_MOD, E" +
                  "CF_MOD FROM E_SPED_C405";
cmd.Connection = conn;


using(var dr = cmd.ExecuteReader())
{
    var list1= new List<string>();

-->>       while(dr.Read()) //Here i get the exception NullReference
    {
        list1.Add(dr["COD_MOD"].ToString());
    }
}

这是堆栈跟踪

em FirebirdSql.Data.Common.DbValue.GetString()
em FirebirdSql.Data.Embedded.XsqldaMarshaler.GetBytes(DbField field)
em FirebirdSql.Data.Embedded.XsqldaMarshaler.MarshalManagedToNative(Charset charset, Descriptor descriptor)
em FirebirdSql.Data.Embedded.FesStatement.Fetch()
em FirebirdSql.Data.Firebird.FbCommand.Fetch()
em FirebirdSql.Data.Firebird.FbDataReader.Read()
em IntegraEstoklus._Default.Page_Load(Object sender, EventArgs e) on    c:\Users\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\Default.aspx.cs:linha 30
em System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
em System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
em System.Web.UI.Control.OnLoad(EventArgs e)
em System.Web.UI.Control.LoadRecursive()
em System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Enviroment.Stacktrace

em System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
em System.Environment.get_StackTrace()
em FirebirdSql.Data.Common.DbValue.GetString()
em FirebirdSql.Data.Embedded.XsqldaMarshaler.GetBytes(DbField field)
em FirebirdSql.Data.Embedded.XsqldaMarshaler.MarshalManagedToNative(Charset charset, Descriptor descriptor)
em FirebirdSql.Data.Embedded.FesStatement.Fetch()
em FirebirdSql.Data.Firebird.FbCommand.Fetch()
em FirebirdSql.Data.Firebird.FbDataReader.Read()
em IntegraEstoklus._Default.Page_Load(Object sender, EventArgs e) na c:\Users\Gabriel\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\Default.aspx.cs:linha 34
em System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
em System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
em System.Web.UI.Control.OnLoad(EventArgs e)
em System.Web.UI.Control.LoadRecursive()
em System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
em System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
em System.Web.UI.Page.ProcessRequest()
em System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
em System.Web.UI.Page.ProcessRequest(HttpContext context)
em ASP.default_aspx.ProcessRequest(HttpContext context) na c:\Users\Gabriel\AppData\Local\Temp\Temporary ASP.NET Files\root\fa427f85\c637233d\App_Web_dd0adkex.0.cs:linha 0
em System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
em System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
em System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(Exception error)
em System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
em System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
em System.Web.HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
em System.Web.HttpRuntime.ProcessRequest(HttpWorkerRequest wr)
em Microsoft.VisualStudio.WebHost.Request.Process()
em Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn)

0 个答案:

没有答案