I have been trying to refresh my database data to see if my database works and I get this error:
This database cannot be imported.it is either an unsupported SQL Server version or an unsupported database compatibility
I have looked for some answers on the internet but so far I am lost and I have no idea what to do.
This is my web.config
:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6.1"/>
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<connectionStrings>
<add name="StarterSite"
connectionString="Data Source=|DataDirectory|\StarterSite.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
....
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0"/>
<add name="Microsoft SQL Server Compact Data Provider 4.0"
invariant="System.Data.SqlServerCe.4.0"
description=".NET Framework Data Provider for Microsoft SQL Server Compact"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
....
</configuration>
added my ADO Code incase it helps
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
/// Summary description for MyAdoHelper
/// פעולות עזר לשימוש במסד נתונים מסוג
/// SQL SERVER
/// App_Data המסד ממוקם בתקיה
/// </summary>
public class MyAdoHelper
{
public MyAdoHelper()
{
//
// TODO: Add constructor logic here
//
}
public static SqlConnection ConnectToDb(string fileName)
{
string path = HttpContext.Current.Server.MapPath("App_Data/");//מיקום מסד בפורוייקט
path += fileName;
string connString = @"Data Source=(LocalDB)\MSSQLLocalDB; AttachDbFilename =" + path + ";Integrated Security=True";
SqlConnection conn = new SqlConnection(connString);
return conn;
}
/// <summary>
/// To Execute update / insert / delete queries
/// הפעולה מקבלת שם קובץ ומשפט לביצוע ומבצעת את הפעולה על המסד
/// </summary>
public static void DoQuery(string fileName, string sql)//הפעולה מקבלת שם מסד נתונים ומחרוזת מחיקה/ הוספה/ עדכון
//ומבצעת את הפקודה על המסד הפיזי
{
SqlConnection conn = ConnectToDb(fileName);
//conn.Close();
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
com.ExecuteNonQuery();
com.Dispose();
conn.Close();
}
/// <summary>
/// To Execute update / insert / delete queries
/// הפעולה מקבלת שם קובץ ומשפט לביצוע ומחזירה את מספר השורות שהושפעו מביצוע הפעולה
/// </summary>
public static int RowsAffected(string fileName, string sql)//הפעולה מקבלת מסלול מסד נתונים ופקודת עדכון
//ומבצעת את הפקודה על המסד הפיזי
{
SqlConnection conn = ConnectToDb(fileName);
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
int rowsA = com.ExecuteNonQuery();
conn.Close();
return rowsA;
}
/// <summary>
/// הפעולה מקבלת שם קובץ ומשפט לחיפוש ערך - מחזירה אמת אם הערך נמצא ושקר אחרת
/// </summary>
public static bool IsExist(string fileName, string sql)//הפעולה מקבלת שם קובץ ומשפט בחירת נתון ומחזירה אמת אם הנתונים קיימים ושקר אחרת
{
SqlConnection conn = ConnectToDb(fileName);
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
SqlDataReader data = com.ExecuteReader();
bool found;
found = (bool)data.Read();// אם יש נתונים לקריאה יושם אמת אחרת שקר - הערך קיים במסד הנתונים
conn.Close();
return found;
}
public static DataTable ExecuteDataTable(string fileName, string sql)
{
SqlConnection conn = ConnectToDb(fileName);
conn.Open();
SqlDataAdapter tableAdapter = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
tableAdapter.Fill(dt);
return dt;
}
public static void ExecuteNonQuery(string fileName, string sql)
{
SqlConnection conn = ConnectToDb(fileName);
conn.Open();
SqlCommand command = new SqlCommand(sql, conn);
command.ExecuteNonQuery();
conn.Close();
}
public static string printDataTable(string fileName, string sql)//הפעולה מקבלת שם קובץ ומשפט בחירת נתון ומחזירה אמת אם הנתונים קיימים ושקר אחרת
{
DataTable dt = ExecuteDataTable(fileName, sql);
string printStr = "<table border='1'>";
foreach (DataRow row in dt.Rows)
{
printStr += "<tr>";
foreach (object myItemArray in row.ItemArray)
{
printStr += "<td>" + myItemArray.ToString() + "</td>";
}
printStr += "</tr>";
}
printStr += "</table>";
return printStr;
}
}
Your code is using the (LocalDB)\\MSSQLLocalDB
instance which is SQL Server Express LocalDB - this is the full SQL Server - NOT the Compact Edition.
So you need to change your config to be something like this:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6.1"/>
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<connectionStrings>
<add name="StarterSite"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|YourDatabase.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
....
....
</configuration>
You don't need any entries under <system.data><DbProviderFactories>
since those are already in place in the machine-wide machine.config
on your system.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.