0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Alexander Bell
  • 7,842
  • 3
  • 26
  • 42
  • `The type initializer for 'System.Data.SqlServerCe.SqlCeConnection' threw an exception` Is there an inner exception? – mason Apr 12 '15 at 23:13
  • Please continue to add the nested inner exceptions to your post until you find the innermost one. – mason Apr 12 '15 at 23:28
  • May I ask you a question: there's already been a discussion on similar issue (http://stackoverflow.com/questions/8952054/can-i-use-sql-server-ce-in-a-medium-trust-environment-by-just-deploying-the-dlls), so should I modify/add something to web.config pertinent to particular SqlCE assembly? Thanks – Alexander Bell Apr 12 '15 at 23:34
  • I don't even know what your error is because you haven't posted the actual exception information. But your free to try out whatever you want. – mason Apr 12 '15 at 23:35
  • The inner exception is "System.Data.SqlServerCe.KillBitHelper". Before going deeper into exception stack (it's quite labor-intensive process in remote hosting) I would like to know if this issue already has been addressed: it looks like some folks faced the similar problem that was discussed in Erik's blog: http://erikej.blogspot.com/2011/10/sql-server-compact-40-under-aspnet.html . Probably I would wait for his response. Thanks, – Alexander Bell Apr 12 '15 at 23:47
  • There's going to be an inner exception on that one too, hence why I said you need to continue to add the nested inner exception until you find the innermost one. And you don't have to obtain it via remote debugging. You can implement error logging and obtain the information that way. – mason Apr 12 '15 at 23:49

0 Answers0