SQL CE 3.5 tidak bekerja dengan ASP.NET, Anda harus menggunakan 4.0 CTP.
Unduh dari di sini .
Instal waktu proses.
Salin konten direktori berikut (termasuk folder x86 dan amd64) ke folder bin aplikasi ASP.NET Anda:C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Private
PERBARUI:Gunakan System.Data.SqlServerCe.dll dari folder Desktop untuk menghindari masalah Kepercayaan Sedang
myapp\bin\
System.Data.SqlServerCe.dll
myapp\bin\x86
sqlceca40.dll
sqlcecompact40.dll
sqlceer40EN.dll
sqlceme40.dll
sqlceqp40.dll
sqlcese40.dll
myapp\bin\amd64
sqlceca40.dll
sqlcecompact40.dll
sqlceer40EN.dll
sqlceme40.dll
sqlceqp40.dll
sqlcese40.dll
Tambahkan referensi ke file System.Data.SqlServerCe.dll yang baru saja Anda masukkan ke folder /bin Anda.
Tempatkan file SQL Compact sdf di folder App_Data Anda.
Tambahkan string koneksi:
<connectionStrings>
<add name ="NorthWind"
connectionString="data source=|DataDirectory|\Nw40.sdf" />
</connectionStrings>
Menghubung! :-)
using System.Data.SqlServerCe;
protected void Page_Load(object sender, EventArgs e)
{
using (SqlCeConnection conn = new SqlCeConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
conn.Open();
using (SqlCeCommand cmd = new SqlCeCommand("SELECT TOP (1) [Category Name] FROM Categories", conn))
{
string valueFromDb = (string)cmd.ExecuteScalar();
Response.Write(string.Format("{0} Time {1}", valueFromDb, DateTime.Now.ToLongTimeString()));
}
}
}