In this post I'm going to give a solution for the issue I faced when deploying my C# windows form App developed using Private deployment of SQL Server Compact 3.5 SP2.
The issue was after installing the app when I tried to run the application it gave me the following error message.
Description:
Stopped working
Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: ARMS.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 52845d57
Problem Signature 04: System.Data.SqlServerCe
Problem Signature 05: 3.5.1.0
Problem Signature 06: 4b743b2d
Problem Signature 07: 15c
Problem Signature 08: 12
Problem Signature 09: System.Data.SqlServerCe.SqlCe
OS Version: 6.1.7600.2.0.0.256.1
Locale ID: 1033
Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt
There might be looooooods of other easy ways to find this problem and quickly solve it but this was my first time publishing a C# app & using a compact database...so bear with me :) I'm posting this since I got an up vote for my question related to this issue in stack-overflow and I'm guessing there are other coders who are in similar messed up situation like I was so I'm trying to help them :)
- Developing machine WIN 7 x64
- Targeted Machine WIN 7 x86
So this is how I solved it.
First I saw some posts saying that they tried to debug using Visual Studio to find the exact error.
- So I installed Visual Studio 2010 on the targeted machine then when I Run the app other than Close The application option it gave debug the application option as well so when debugged It gave me the name of the Exception. It said "SqlServerCeException" :D
- The I searched for solutions there were tons of solutions first this link grabbed my attention since it was a nice way to really know what went wrong.
- So I modified my connection code into
..............
..............
if (conn.State.ToString() == "Closed")
{
try
{
conn.Open(); //surround conn.open( ) witha try-catch( ) block
}
catch(SqlCeException e)
{
MessageBox.Show(e.Message);
ShowErrors(e); //use the ShowErrors method implemented on the same page
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
................. ................. }
//ShowErrors method implementation public static string ShowErrors(System.Data.SqlServerCe.SqlCeException e)
{
System.Data.SqlServerCe.SqlCeErrorCollection errorCollection = e.Errors;
StringBuilder bld = new StringBuilder();
Exception inner = e.InnerException;
if (!string.IsNullOrEmpty(e.HelpLink))
{
bld.Append("\nCommand text: ");
bld.Append(e.HelpLink);
}
if (null != inner)
{
bld.Append("\nInner Exception: " + inner.ToString());
}
// Enumerate the errors to a message box.
foreach (System.Data.SqlServerCe.SqlCeError err in errorCollection)
{
bld.Append("\n Error Code: " + err.HResult.ToString("X", System.Globalization.CultureInfo.InvariantCulture));
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.IsNullOrEmpty(errPar)) bld.Append("\n Err. Par. : " + errPar);
}
}
return bld.ToString();
}
(Newly added lines are shown in blue)
- And I published the app again and reinstalled the app then when I tried to run the app before Stopped Working Popup message it gave me another popup message with exact details of the error and it said " Access to the database file is not allowed ".
- So I doubled check if I typed "
|DataDirectory|" instead of the path to the .sdf file,
eg:
connectionString = " Data Source=|DataDirectory|myDB.sdf "
- Then I went to the app installed location I gave it as "C:\Program Files\ARMS" and with in the ARMS folder was the myDB.sdf file. Then I set the .sdf file permission to allow Full Control for the currently logged-in profile in the security tab on the properties dialog that I got when I right clicked on the .sdf file.
Then I tried running the earlier installed app and this time it gave me no errors......
easy as that :D
Hope this helped....Please leave a comment.
Suggestions for improvements are also welcomed :)
...Happy Coding...
No comments:
Post a Comment