无法打开数据库,因为它是版本706.此服务器支持655及更早版本。不支持降级路径

时间:2022-07-17 06:26:33

I have database files in my App_Data folder and my web config looks like this

我的App_Data文件夹中有数据库文件,我的web配置如下所示

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="TicketsConnectionString" 
         connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Tickets.mdf;Integrated Security=SSPI;User Instance=True;" 
   providerName="System.Data.SqlClient" />

  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
</configuration>

I have Default.aspx page

我有Default.aspx页面

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:TextBox ID="LastName" runat="server"></asp:TextBox>
        <asp:TextBox ID="FirstName" runat="server"></asp:TextBox>
        <asp:TextBox ID="Phone1" runat="server"></asp:TextBox>
        <asp:TextBox ID="Phone2" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        <br />
        <br />
        <asp:Label ID="DisplayMessage" runat="server" style="color: #FF0000" Visible="false" />
        <br />
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TicketsConnectionString %>" SelectCommand="SELECT * FROM [Employee]" DeleteCommand="DELETE FROM [Employee] WHERE [EmpID] = @EmpID" InsertCommand="INSERT INTO [Employee] ([LastName], [FirstName], [Phone1], [Phone2]) VALUES (@LastName, @FirstName, @Phone1, @Phone2)" UpdateCommand="UPDATE [Employee] SET [LastName] = @LastName, [FirstName] = @FirstName, [Phone1] = @Phone1, [Phone2] = @Phone2 WHERE [EmpID] = @EmpID">
            <DeleteParameters>
                <asp:Parameter Name="EmpID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="Phone1" Type="String" />
                <asp:Parameter Name="Phone2" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="Phone1" Type="String" />
                <asp:Parameter Name="Phone2" Type="String" />
                <asp:Parameter Name="EmpID" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>

        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataKeyNames="EmpID" DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical">
            <AlternatingRowStyle BackColor="#CCCCCC" />
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="EmpID" HeaderText="EmpID" InsertVisible="False" ReadOnly="True" SortExpression="EmpID" />
                <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
                <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
                <asp:BoundField DataField="Phone1" HeaderText="Phone1" SortExpression="Phone1" />
                <asp:BoundField DataField="Phone2" HeaderText="Phone2" SortExpression="Phone2" />
            </Columns>
            <FooterStyle BackColor="#CCCCCC" />
            <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#808080" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#383838" />
        </asp:GridView>

    </div>
    </form>
</body>
</html>

and one Default.aspx.cs page

和一个Default.aspx.cs页面

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.DataBind();
    }

    string connectionString = ConfigurationManager.ConnectionStrings["TicketsConnectionString"].ConnectionString;

    protected void Button1_Click(object sender, EventArgs e)
    {


        DataSet ds = new DataSet();
        SqlConnection con = new SqlConnection(connectionString);
        SqlCommand cmd = new SqlCommand("InsertIntoEmployee", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@LastName", SqlDbType.NVarChar).Value = LastName.Text;
        cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar);
        cmd.Parameters.Add("@Phone1", SqlDbType.NVarChar);//SqlDbType.NVarChar allowed to insert Russian letters
        cmd.Parameters.Add("@Phone2", SqlDbType.NVarChar);
        cmd.Parameters["@LastName"].Value = LastName.Text;
        cmd.Parameters["@FirstName"].Value = FirstName.Text;
        cmd.Parameters["@Phone1"].Value = Phone1.Text;
        cmd.Parameters["@Phone2"].Value = Phone2.Text;
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();



        DisplayMessage.Text = "Запись добавлена.";
            DisplayMessage.Visible = true;

    }
}

and it throwing this error

它抛出这个错误

The database 'G:\SITES\WEBSITE6\APP_DATA\TICKETS.MDF' cannot be opened because it is version 706. This server supports version 655 and earlier. A downgrade path is not supported.
Could not open new database 'G:\SITES\WEBSITE6\APP_DATA\TICKETS.MDF'. CREATE DATABASE is aborted.
An attempt to attach an auto-named database for file G:\sites\WebSite6\App_Data\Tickets.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: The database 'G:\SITES\WEBSITE6\APP_DATA\TICKETS.MDF' cannot be opened because it is version 706. This server supports version 655 and earlier. A downgrade path is not supported.
Could not open new database 'G:\SITES\WEBSITE6\APP_DATA\TICKETS.MDF'. CREATE DATABASE is aborted.
An attempt to attach an auto-named database for file G:\sites\WebSite6\App_Data\Tickets.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Source Error: 


Line 14:     protected void Page_Load(object sender, EventArgs e)
Line 15:     {
Line 16:         GridView1.DataBind();
Line 17:     }
Line 18: 

I thought there is some problem in connection Strings but for me everything looks fine, and my question how to fix this problem?

我认为连接字符串有一些问题,但对我来说一切都很好,我的问题是如何解决这个问题?

4 个解决方案

#1


10  

Version 706 is a database file from Sql Server 2012
Version 665 is a database file from Sql Server 2008R2 (post SP1 ?)

版本706是来自Sql Server 2012的数据库文件版本665是来自Sql Server 2008R2的数据库文件(后SP1?)

http://conceptdev.blogspot.com/2009/04/mdf-cannot-be-opened-because-it-is.html

http://conceptdev.blogspot.com/2009/04/mdf-cannot-be-opened-because-it-is.html

#2


1  

Here is Tested Solution, 1st Connect both Server in your SQL Server Management Studio and then RUN the 1st Code Block

这是经过测试的解决方案,首先在SQL Server Management Studio中连接两个服务器,然后运行第一个代码块

--1st Run this (One Time)
EXEC sp_addlinkedserver  
@server='YOUR_SERVER_IP', -- here you can specify the name of the linked server  
@srvproduct='',       
@provider='sqlncli', -- using SQL Server Native Client  
@datasrc='YOUR_SERVER_IP',   -- add here your server name  
@location='',  
@provstr='',  
@catalog='DATABASE_NAME'

Then Run this Individually

然后单独运行此命令

SELECT TOP(100) * 
FROM LOCAL_TABLE A, [YOUR_SERVER_IP].DATABASE_NAME.dbo.TABLE_NAME C
WHERE A.ID=C.ID

#3


0  

If you’re trying to attach to a local db use LocalDb (since vs2012, sql2012), ie:

如果您尝试连接到本地数据库,请使用LocalDb(自vs2012,sql2012),即:

Data Source=(LocalDB)\v11.0;AttachDbFilename= (etc)

#4


0  

I'm sure the problem was that aspnetdb.mdf can't open.

我确定问题是aspnetdb.mdf无法打开。

Sometimes this file gets corrupted. The problem was that I can't validate login page.

有时这个文件被破坏了。问题是我无法验证登录页面。

After deleting(and replacing) my login form control, the problem was solved.

删除(并替换)我的登录表单控件后,问题就解决了。

The reason for this was because control from asp.net uses aspnet membership. I replaced my login control (with javascript) with CSS style and remove all related files and that solved it.

原因是因为asp.net的控制使用了aspnet成员资格。我用CSS样式替换了我的登录控件(使用javascript)并删除了所有相关文件并解决了它。

I hope this helps someone.

我希望这可以帮助别人。

#1


10  

Version 706 is a database file from Sql Server 2012
Version 665 is a database file from Sql Server 2008R2 (post SP1 ?)

版本706是来自Sql Server 2012的数据库文件版本665是来自Sql Server 2008R2的数据库文件(后SP1?)

http://conceptdev.blogspot.com/2009/04/mdf-cannot-be-opened-because-it-is.html

http://conceptdev.blogspot.com/2009/04/mdf-cannot-be-opened-because-it-is.html

#2


1  

Here is Tested Solution, 1st Connect both Server in your SQL Server Management Studio and then RUN the 1st Code Block

这是经过测试的解决方案,首先在SQL Server Management Studio中连接两个服务器,然后运行第一个代码块

--1st Run this (One Time)
EXEC sp_addlinkedserver  
@server='YOUR_SERVER_IP', -- here you can specify the name of the linked server  
@srvproduct='',       
@provider='sqlncli', -- using SQL Server Native Client  
@datasrc='YOUR_SERVER_IP',   -- add here your server name  
@location='',  
@provstr='',  
@catalog='DATABASE_NAME'

Then Run this Individually

然后单独运行此命令

SELECT TOP(100) * 
FROM LOCAL_TABLE A, [YOUR_SERVER_IP].DATABASE_NAME.dbo.TABLE_NAME C
WHERE A.ID=C.ID

#3


0  

If you’re trying to attach to a local db use LocalDb (since vs2012, sql2012), ie:

如果您尝试连接到本地数据库,请使用LocalDb(自vs2012,sql2012),即:

Data Source=(LocalDB)\v11.0;AttachDbFilename= (etc)

#4


0  

I'm sure the problem was that aspnetdb.mdf can't open.

我确定问题是aspnetdb.mdf无法打开。

Sometimes this file gets corrupted. The problem was that I can't validate login page.

有时这个文件被破坏了。问题是我无法验证登录页面。

After deleting(and replacing) my login form control, the problem was solved.

删除(并替换)我的登录表单控件后,问题就解决了。

The reason for this was because control from asp.net uses aspnet membership. I replaced my login control (with javascript) with CSS style and remove all related files and that solved it.

原因是因为asp.net的控制使用了aspnet成员资格。我用CSS样式替换了我的登录控件(使用javascript)并删除了所有相关文件并解决了它。

I hope this helps someone.

我希望这可以帮助别人。