如何修复“无法导入此数据库。它是不受支持的SQL Server版本或不受支持的数据库兼容性。”

时间:2019-12-26 02:05:04

标签: c# visual-studio

我创建了一个基于服务的数据库,每次尝试插入数据时,应用程序都可以正常工作,但是当我重新加载数据库并希望查看数据时,它显示此消息"This database cannot be imported. It is either an unsupported SQL Server version or an unsupported database compatibility.",而数据却没有更新,我不知道该如何解决,已经从SO搜索了一些解决方案,但仍然没有得到它..

如果您需要一些详细信息,可以在评论中提问*因为我不知道要在其中添加什么内容

编辑: App.conf

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="Database1Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\Database1.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;"
      providerName="System.Data.EntityClient" />
    <add name="Database1Entities1" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\Database1.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;"
      providerName="System.Data.EntityClient" />
    <add name="TravelokaCMR.Properties.Settings.Database1ConnectionString"
      connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

我如何插入数据

Database1Entities1 db = new Database1Entities1();
 foreach (string files in filesindirectory)
            {
                string name = Path.GetFileName(files);
                string subname = name.Substring(10, 8);
                DateTime subTime = DateTime.ParseExact(subname, "yyyyMMdd", null);
                TimeSpan span = otime2.Subtract(subTime);

                if (span.Days < 2)
                {
                    // Console.WriteLine(files);
                    foreach (string subfiles in Directory.GetFiles(files))
                    {
                        xlWb = xlApp.Workbooks.Open(subfiles);
                        xlWs = xlWb.Sheets[1];
                        xlRange = xlWs.UsedRange;
                        rowFile = xlRange.Rows.Count;
                        colFile = xlRange.Columns.Count;

                        dataFile = new string[rowFile][];

                        for (int i = 0; i < dataFile.Length; i++)
                        {
                            dataFile[i] = new string[colFile];
                        }

                        for (int i = 0; i < rowFile; i++)
                        {

                                try
                                {
                                    dataFile[i][0] = xlWs.Cells[i + 1,  1].value2.ToString();
                                    //MessageBox.Show(dataMapping[i][j]);
                                }
                                catch (Exception ee)
                                {
                                    dataFile[i][0] = "";
                                }

                        }

                        for (int i = 0; i < rowFile; i++)
                        {
                            CMRTable cmr = new CMRTable();
                            items = dataFile[i][0].Split(';');

                            cmr.Merchant_name = items[1];
                            cmr.Sett_date = items[2];
                            cmr.Proc_date = items[3];
                            cmr.Mid = items[4];
                            cmr.cardtype = items[5];
                            cmr.Trx_date = items[6];
                            cmr.Jam_trx = items[7];
                            cmr.Auth = items[8];
                            cmr.Cardno = items[9];
                            cmr.Trx_type = items[10];
                            cmr.amount = items[11];
                            cmr.rate = items[12];
                            cmr.disc_amt = items[13];
                            cmr.tenor_ins = items[14];
                            cmr.rate_ins = items[15];
                            cmr.disc_ins = items[16];
                            cmr.net_amt = items[17];
                            cmr.purchase_id = items[18];
                            cmr.merchant_descriptor = items[19];
                            db.AddToCMRTables(cmr);
                            db.SaveChanges();

                        }

1 个答案:

答案 0 :(得分:0)

聊天后,发现了以下内容。

在查看您的连接字符串时,似乎您的mdf路径不正确。请研究将| DataDirectory | \替换为实际路径,然后重试该过程。

  <connectionStrings>
    <add name="Database1Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=**|DataDirectory|**\Database1.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;"
      providerName="System.Data.EntityClient" />
    <add name="Database1Entities1" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=**|DataDirectory|**\Database1.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;"
      providerName="System.Data.EntityClient" />
    <add name="TravelokaCMR.Properties.Settings.Database1ConnectionString"
      connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=**|DataDirectory|**\Database1.mdf;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

注意::每个连接字符串都指向Database1.mdf。不知道是不是故意的。