Monday, March 26, 2012

Problem with SQL Ce Connection

I have a strange problem while using sqlceconnection object. I'm using Sql Server 2005 Compact edition. While I'm trying to open the connection, an exception with blank message is raised, But if I open Query analyser on my windows ce 5.0 device and try to run the application again, it works(connection is getting opened)...Anyone faced this issue before?

Any help is greatly apreciated

JK789 wrote:

I have a strange problem while using sqlceconnection object. I'm using Sql Server 2005 Compact edition. While I'm trying to open the connection, an exception with blank message is raised, But if I open Query analyser on my windows ce 5.0 device and try to run the application again, it works(connection is getting opened)...Anyone faced this issue before?

Any help is greatly apreciated

I'm using VS2005 with SP1

|||Out of memory? When do you open your connection in your app (early or later)?|||

Hi,

Below is the code I'm using to open the connection.

Code Snippet

publicDataSet GetDataToPopulate(string sSql)

{

string sDataSource = ConfigurationSettings.AppSettings["db"].ToString();

SqlCeDataAdapter da = newSqlCeDataAdapter();

SqlCeCommand cmdSelect = newSqlCeCommand();

DataSet ds = newDataSet();

if(!System.IO.File.Exists(sDataSource))

throw(newApplicationException("Database not exists"));

SqlCeConnection cn=newSqlCeConnection("Data Source = " + sDataSource);

try

{

cn.Open();

cmdSelect.Connection = cn;

cmdSelect.CommandText = sSql;

cmdSelect.CommandType = CommandType.Text ;

da.SelectCommand = cmdSelect;

da.Fill(ds);

return ds;

}

catch(SqlCeException ex)

{

sError = ex.Message;

returnnull;

}

catch(Exception ex1)

{

sError = ex1.Message ;

returnnull;

}

finally

{

ds.Dispose();

ds.Dispose();

cmdSelect.Dispose();

if(cn.State == ConnectionState.Open )

cn.Close();

cn.Dispose();

}

}

|||You are creating a dataset. Is your table large, then the dataset will take a large amount of memory. In order to get the exact SQL CE error message, see this sample (getting ex.Message is not enough!) : http://msdn2.microsoft.com/en-us/library/ms174079.aspx|||

I am having the identical problem. Does anyone know of a fix or work around?

In the code below, open throws a blank error. I have tested the code with and without tables in the referenced database. If the path to the database file is wrong I get a specific error so it’s not a path issue. Any ideas?

private SqlCeConnection loadDatabase(string Path)
{
SqlCeConnection temp_cn = null;
try
{
temp_cn = new SqlCeConnection("Data Source=" + Path + "");
temp_cn.Open();
}
catch (SqlCeException sqlex)
{
foreach (SqlCeError sqlERROR in sqlex.Errors)
{
MessageBox.Show(sqlERROR.Message);
}
}
return temp_cn;
}

Thanks,

Matthew

|||

The error now produced from this code from the posting above is as follows:

Error Code: 8007000E

Message :

Minor Err: 0

Source: SQL Server Compact Edition ADO.Net Data Provider

private SqlCeConnection loadDatabase(string Path)

{

SqlCeConnection temp_cn = null;

try

{

temp_cn = new SqlCeConnection("Data Source=" + Path + "");

temp_cn.Open();

temp_cn.Close();

}

catch (SqlCeException e)

{

ShowErrors(e);

}

return temp_cn;

}

// Error handling routine that generates an error message

public static void ShowErrors(SqlCeException e)

{

SqlCeErrorCollection errorCollection = e.Errors;

StringBuilder bld = new StringBuilder();

Exception inner = e.InnerException;

if (null != inner)

{

MessageBox.Show("Inner Exception: " + inner.ToString());

}

// Enumerate the errors to a message box.

foreach (SqlCeError err in errorCollection)

{

bld.Append("\n Error Code: " + err.HResult.ToString("X"));

bld.Append("\n Message : " + err.Message);

bld.Append("\n Minor Err.: " + err.NativeError);

bld.Append("\n Source : " + err.Source);

// Enumerate each numeric parameter for the error.

foreach (int numPar in err.NumericErrorParameters)

{

if (0 != numPar) bld.Append("\n Num. Par. : " + numPar);

}

// Enumerate each string parameter for the error.

foreach (string errPar in err.ErrorParameters)

{

if (String.Empty != errPar) bld.Append("\n Err. Par. : " + errPar);

}

MessageBox.Show(bld.ToString());

bld.Remove(0, bld.Length);

}

}

|||The error indicates an out of memory condition. Which device are you runnng on: Desktop, Pocket PC, Smartphone?

No comments:

Post a Comment