OpenException

Dec 7, 2011 at 10:28 AM

Hi,

I created a WP7 app that uses your database and it works correctly. Now I'm re-organizing my project in order to use new Mango features like task-schedulers. To do this I moved all the db handler into a separate project. I use the dll of this project from both the app and the task scheduler.

One of the first test I'm doing is the following. I load on the emulator a xap file which installs the older pre-mango version and I run it the first time in order to initialize the db.

Then I try to update the app with the new mango version. When I launch the app I have, at the beginning, the following error:

A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
A first chance exception of type 'SilverlightPhoneDatabase.Exceptions.OpenException' occurred in SilverlightPhoneDatabase.dll
OpenDB - ex:Cannot open database. See InnerException for details, inner ex:Value can not be null. 

the function OpenDB is the simple following one:

public bool OpenDB()
{
bool isError = false;
try
{
db = Database.OpenDatabase(dbName);
}
catch (Exception ex)
{
isError = true;
Debug.WriteLine("OpenDB - ex:" + ex.Message + ", inner ex:" + ex.InnerException.Message);
}
return isError;

 

any idea on the cause? Almost all the tables are the same of the previous version. In just one table I added a field. I also tried to remove this new filed but the issue is still present. I have all the parameterless constructors of the tables.

Is the moving into a new project the cause of the issue?  If so, can you please help me in understanding why?

thanks,

Dec 8, 2011 at 2:04 AM

You do not have a check if database already exists.  The emulator will wipe your isolated storage if you rebuild the project, that is likley why you are getting the error.  You can always use isolated storate utility and manually copy the files over to / from the emulator.

Hope this helps.

Dec 8, 2011 at 7:18 AM

Hi Sergey,

first of all thanks for your support... this is not the first time I ask you for help and you are always quick in answering....

Unfortunately the check on database existence does not solve the problem. After having wrote the post to you I had the same idea and I tried to add this check but I'm still facing the problem.

The check indicates the existence of database but the "open" command continues to give me the same error.....

Any other suggestion?

Dec 8, 2011 at 10:28 PM

Maybe name is null somehow?  Can you capture the full stack and paste it in?

Thanks.

Dec 11, 2011 at 7:07 PM

Dear Sergey,

a different question about the same problem. Using my app, it can happen that there's a  OpenException at database opening. I tried to look at the code of the database and I inserted some prints inside.

Here is reported the "edited" code

 

public static Database OpenDatabase(string databaseName, string password, bool useLazyLoading)
{
Debug.WriteLine("OpenDatabase");
if (!DoesDatabaseExists(databaseName))
{
throw new DatabaseDoesNotExistsException(string.Format(DatabaseResources.DatabaseDoesNotExistsExceptionText, databaseName));
}
try
{
Database returnValue = new Database(databaseName, password, useLazyLoading);
Debug.WriteLine("OpenDatabase - 1");
string[] parts;
Type tableType = null;
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
Debug.WriteLine("OpenDatabase - 2");
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(databaseName, FileMode.Open, store))
{
StreamReader reader = new StreamReader(stream);
Debug.WriteLine("OpenDatabase - 3");
string content;
content = reader.ReadToEnd();
Debug.WriteLine("OpenDatabase - 4");
if (!string.IsNullOrEmpty(password))
{
content = Cryptography.Decrypt(content, password);
}
Debug.WriteLine("OpenDatabase - 5");
parts = content.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
stream.Close();
}
Debug.WriteLine("OpenDatabase - 6 - parts.len:" + parts.Length);
if (parts != null)
{
for (int counter = 1; counter < parts.Length; counter++)
{
Debug.WriteLine("OpenDatabase - 7." + counter.ToString());
string content = string.Empty; ;
string rowTypeString = parts[counter];
Type rowType = Type.GetType(rowTypeString);
tableType = typeof(Table<>).MakeGenericType(new Type[] { rowType });
if (!useLazyLoading)
{
string fileName = string.Concat(databaseName, ".", rowType.FullName);
using (IsolatedStorageFileStream tableStream = new IsolatedStorageFileStream(fileName, FileMode.Open, store))
{
returnValue.LoadTable(tableStream, tableType);
tableStream.Close();
}
}
else
{
ITable currentTable = (ITable)Activator.CreateInstance(tableType);
currentTable.SetTableDefinition(returnValue._databaseName, returnValue._password);
List<ITable> tables = new List<ITable>(returnValue._tables);
tables.Add(currentTable);
returnValue._tables = new ReadOnlyCollection<ITable>(tables);
returnValue._loadedTables.Add(rowType, false);
}
}
}
}
return returnValue;
}
catch (Exception ex)
{
throw new OpenException(ex);
}

}

and following is the print when opening the app:

OpenDatabase
OpenDatabase - 1
OpenDatabase - 2
OpenDatabase - 3
OpenDatabase - 4
OpenDatabase - 5
OpenDatabase - 6 - parts.len:18
OpenDatabase - 7.1
OpenDatabase - 7.2
OpenDatabase - 7.3
OpenDatabase - 7.4
OpenDatabase - 7.5
OpenDatabase - 7.6
OpenDatabase - 7.7
OpenDatabase - 7.8
OpenDatabase - 7.9
OpenDatabase - 7.10
'UI Task' (Managed): Loaded 'System.SR.dll'
A first chance exception of type 'System.Xml.XmlException' occurred in System.Xml.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Xml.dll
A first chance exception of type 'SilverlightPhoneDatabase.Exceptions.OpenException' occurred in SilverlightPhoneDatabase.dll
OpenDB - ex:Cannot open database. See InnerException for details, inner ex:There is an error in XML document (0, 0).
A first chance exception of type 'System.NullReferenceException' occurred in MoneyManagerPro.dll

 

I will continue to try to understand what is happening but your help, as the creator of the db, would be precious.

 

thanks,

Dec 11, 2011 at 7:39 PM

Dear Sergey,

I'm continuing to test the app in order to find the error. By repeating the open - close the app, maybe I found something useful: When exiting the app I sometimes have the following error:

SaveDB - ex:Cannot save data. See InnerException for details, innerException:SilverlightPhoneDatabase.Exceptions.SaveException: Cannot save data. See InnerException for details ---> SilverlightPhoneDatabase.Exceptions.SaveException: Cannot save data. See InnerException for details ---> System.Threading.ThreadAbortException: ThreadAbortException
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[] index, StackCrawlMark& stackMark)
at System.Reflection.RuntimePropertyInfoA first chance exception of type 'System.Threading.ThreadAbortException' occurred in MoneyManagerPro.dll

SaveDB is the following simple function:

public void SaveDB()
{
   try
   {
     db.Save();
     Debug.WriteLine("SALVATO DB!");
   }
   catch (Exception ex)
   {
     isError = true;

    Debug.WriteLine("SaveDB - ex:" + ex.Message + ", innerException:" + ex.InnerException);
   }
}

Any idea on how to solve the issue?

 

thanks again

 

Apr 28, 2012 at 6:01 PM

I had the same issue, The error was related to serialization. Make sure all the classes which you are creating table for has a default paramenter less constructor.

Hope this helps