SQL CE 3.5 virker ikke med ASP.NET, du skal bruge 4.0 CTP.
Download fra her .
Installer runtime.
Kopier følgende mappeindhold (inklusive x86- og amd64-mapperne) til bin-mappen i din ASP.NET-app:C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Private
OPDATERING:Brug System.Data.SqlServerCe.dll fra skrivebordsmappen for at undgå problemer med medium tillid
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
Tilføj en reference til filen System.Data.SqlServerCe.dll, du lige har lagt i din /bin-mappe.
Placer SQL Compact sdf-filen i din App_Data-mappe.
Tilføj forbindelsesstreng:
<connectionStrings>
<add name ="NorthWind"
connectionString="data source=|DataDirectory|\Nw40.sdf" />
</connectionStrings>
Opret forbindelse! :-)
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()));
}
}
}