I added System.Data.SqlServerCe.dll v3.5 in my ASP.NET Core Web API project, but I'm getting error while connecting to SQL Server CE database.
This is my code:
private static string DbFilePath = @"C:\Git\Forecaster\DB\THSTaxPro.sdf";
private static string DbPassword = "123567";
private static string DbMaxSize = "4090";
public static string ConnectionString = @"Data Source=" + DbFilePath + ";Password=" + DbPassword + ";Max Database Size=" + DbMaxSize + "";
[Route("thsAdditionalincome")]
public async Task<IEnumerable<AdditionalIncome>> thsAdditionalincome(string accountid)
{
try
{
using (var conn = new SqlCeConnection(_connectionString))
{
var query = "select irs_account_id,income_alimony,income_alimony_taxpayer,income_alimony_spouse,income_child_support , income_child_support_taxpayer,income_child_support_spouse ,income_net_business, income_net_business_taxpayer, income_net_business_spouse , income_net_rental , income_net_rental_taxpayer , income_net_rental_spouse , income_pension , income_pension_taxpayer ,income_pension_spouse, income_interest_dividends , income_interest_dividends_taxpayer,income_interest_dividends_spouse, income_social_security,income_social_security_taxpayer,income_social_security_spouse,income_other_1,income_other_1_taxpayer,income_other_2,income_other_2_taxpayer,income_other_2_spouse from t_financial_analysis_individual where IsDeleted=0 and irs_account_id=@accountid";
var parameters = new DynamicParameters();
parameters.Add("@accountid", accountid, DbType.String);
conn.Open();
var results = await conn.QueryAsync<AdditionalIncome>(query, param: new { accountid });
return results.ToList();
}
}
catch (Exception ex)
{
throw ex;
}
}

This is the error I am getting:

SQL CE is out of support. But there is a way you can use SQL CE 3.5 in asp.net core project.
Step1. Go to CE3.5 installation folder. Copy all .dll files except
system.data.sqlserverce.entityto a new folder namedamd64,paste this folder to project root.Step2. from private folder copy
system.data.sqlserverce.dllto project rootYou project root is like

Step3. open .csproj add the following reference
Step4.install nuget package
Microsoft.Windows.Compatibilitylatest version.Now restart your project, SqlCeConnection will work.
All .csproj