So far, I have this ASP.NET web form app project, which contains Microsoft SQL Server CE 4.0 (Compact Edition database file) in Visual Studio 2013 community edition. It's configured as follows (showing the most critical points):
bin
folder:
bin\System.Data.SqlServerCe.dll
bin\System.Data.SqlServerCe.Entity.dll
bin\amd64
bin\amd64\Sqlceca40.dll
bin\amd64\Sqlcecompact40.dll
bin\amd64\ Sqlceer40EN.dll
bin\amd64\Sqlceme40.dll
bin\amd64\Sqlceqp40.dll
bin\amd64\Sqlcese40.dll
bin\amd64\Microsoft.VC90.CRT
bin\amd64\Microsoft.VC90.CRT\Microsoft.VC90.CRT.manifest
bin\amd64\Microsoft.VC90.CRT\msvcr90.dll
bin\x86\Sqlceca40.dll
bin\x86\Sqlcecompact40.dll
bin\x86\Sqlceer40EN.dll
bin\x86\Sqlceme40.dll
bin\x86\Sqlceqp40.dll
bin\x86\Sqlcese40.dll
bin\x86\Microsoft.VC90.CRT
bin\x86\Microsoft.VC90.CRT\Microsoft.VC90.CRT.manifest
bin\x86\Microsoft.VC90.CRT\msvcr90.dll
web.config
contains:
<connectionStrings>
<add name="conn"
connectionString="Persist Security Info = False;File Mode ='Read Write';Encryption Mode=Platform Default;Password='pwd';DataSource=|DataDirectory|\MyDatabase.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
Code-behind contains:
using System.Data.SqlServerCe;
and simple test code snippet listed below:
protected void Page_Load(object sender, EventArgs e)
{
DataTable _dt;
string _testPoint = String.Empty;
try
{
// sample sql statement
string _sql = "SELECT CATEGORY FROM TBL_CATEGORY";
string _connString = System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
#region TEST AREA
// test points to trace the error origin
_testPoint = "tp1";
SqlCeConnection _sqlceConn = new SqlCeConnection();
_testPoint = "tp2";
_sqlceConn.ConnectionString = _connString;
_testPoint = "tp3";
_sqlceConn.Open();
_testPoint = "tp4";
#endregion
#region to be used in production
//using (SqlCeConnection _connSqlCe = new SqlCeConnection(_connString))
//{
// using (SqlCeCommand _commandSqlCe = new SqlCeCommand(_sql, _connSqlCe))
// {
// _commandSqlCe.CommandType = CommandType.Text;
// _connSqlCe.Open();
// using (SqlCeDataReader _dataReaderSqlCe = _commandSqlCe.ExecuteReader(CommandBehavior.CloseConnection))
// {
// _dt = new DataTable();
// _dt.Load(_dataReaderSqlCe);
// _dataReaderSqlCe.Close();
// }
// }
// _connSqlCe.Close();
//}
//int _rowCount = _dt.Rows.Count;
#endregion
}
catch (AccessViolationException ax) { Label1.Text += "A: " + ax.Message; }
catch (DataException dx) { Label1.Text += "D: " + dx.Message; }
catch (Exception ex) { Label1.Text += "X: " + ex.Message; if (ex.InnerException != null) { Label1.Text += ex.InnerException.Message; } }
}
Everything seems OK while running in Visual Studio 2013 IDE. But when deployed to GoDaddy hosting account (note: to the best of my knowledge it's environment set to Medium Trust) it fail at the very first test line:
SqlCeConnection _sqlceConn = new SqlCeConnection();
with exception shown below (including inner exception):
The type initializer for 'System.Data.SqlServerCe.SqlCeConnection' threw an exception.
The type initializer for 'System.Data.SqlServerCe.KillBitHelper' threw an exception.
Apparently, the app does not recognize the referenced SQL Server CE library, even though all .dll
exists on web server (checked it using GoDaddy file management tools).
QUESTION: how to fix this deployment issue?
SUB-QUESTION: Is it possible to use simple x-copy deployment if SQLite database file is used instead of SQL Server CE in Medium Trust environment?