2013-08-21 18 views
5

tôi có các file cơ sở dữ liệu trong thư mục App_Data tôi và cấu hình web của tôi trông như thế nàyKhông thể mở cơ sở dữ liệu vì nó là phiên bản 706. Máy chủ này hỗ trợ phiên bản 655 trở về trước. Một con đường hạ cấp không được hỗ trợ

<?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> 

Tôi có trang 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> 

và một Default.aspx.cs trang

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; 

    } 
} 

và nó ném lỗi này

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: 

Tôi nghĩ rằng có một số vấn đề trong kết nối Strings nhưng đối với tôi mọi thứ đều ổn, và câu hỏi của tôi làm thế nào để khắc phục vấn đề này?

+0

Nâng cấp phiên bản SQL Server của bạn hoặc tạo lại cơ sở dữ liệu trong cùng một phiên bản SQL Server mà bạn đang sử dụng. –

+0

nó được tạo trên cùng một DB yesturday đó là SQL Server Express 2012. tôi vừa sao chép tập tin .mdf từ thư mục dữ liệu DB vào thư mục với dự án của tôi và thay đổi 'ConnectionSting' – Andrey

+1

Bạn đang gắn cơ sở dữ liệu vào một cái gì đó khác với SQL Server 2012. –

Trả lời

0

Nếu bạn đang cố gắng để đính kèm vào một địa phương sử dụng db LocalDb (kể từ vs2012, sql2012), ví dụ:

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

tôi chắc chắn rằng vấn đề là aspnetdb.mdf không thể mở.

Đôi khi tệp này bị hỏng. Vấn đề là tôi không thể xác thực trang đăng nhập.

Sau khi xóa (và thay thế) điều khiển biểu mẫu đăng nhập của tôi, sự cố đã được giải quyết.

Lý do là vì kiểm soát từ asp.net sử dụng aspnet thành viên. Tôi thay thế điều khiển đăng nhập của mình (bằng javascript) với kiểu CSS và xóa tất cả các tệp có liên quan và giải quyết nó.

Tôi hy vọng điều này sẽ giúp ai đó.

+0

Bạn thực sự nên đăng câu hỏi của riêng mình. Điều này ở đây là một vài năm tuổi. Bạn có thể liên kết ngược lại câu hỏi này cho biết lý do tại sao điều này không áp dụng cho bạn hoặc điều gì khác biệt, cũng như bất kỳ điều gì khác bạn thực sự đã thử. Chào mừng bạn đến với SO và chúc bạn may mắn! – Madivad

Các vấn đề liên quan