2015-04-02 60 views
0

我不是一個非常有經驗的程序員,目前我的課程作業項目正在使用Microsoft Visual Studio Express 2013 for Windows Desktop。C#LINQ to SQL插入新記錄幫助 - 錯誤

我目前正在使用LINQ然而到SQL一個新的記錄(我認爲這就是所謂的紀錄,我的意思是行)添加到我的TeacherDetails表時,我點擊按鈕2的錯誤出現說:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.Linq.dll

Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

(我真的不知道手段)

每當我按下去,並嘗試刷新我的表/數據庫出現其他錯誤說:

This database cannot be imported. It is either an unsupported SQL Server version or an unsupported database compatibility

這是

private void button2_Click(object sender, EventArgs e) 
    { 


     ProjectDBDataContext db = new ProjectDBDataContext(@"projectDB.mdf"); 

     TeacherDetail cust = new TeacherDetail(); 

     cust.Surname = "Surname"; 
     cust.First_Name = "name"; 
     cust.Email_Address = "[email protected]"; 
     cust.Title = "Mr"; 
     db.TeacherDetails.InsertOnSubmit(cust); 


     db.SubmitChanges(); 


     this.Hide(); 
     Form1 f1 = new Form1(); 
     f1.ShowDialog();     
    } 

這是我的數據庫代碼啄:

CREATE TABLE [dbo].[TeacherDetails] (
     [TeacherId]  INT   IDENTITY (1, 1) NOT NULL, 
     [First Name] NVARCHAR (50) NULL, 
     [Surname]  NVARCHAR (50) NULL, 
     [Email Address] NVARCHAR (50) NULL, 
     [Password]  NVARCHAR (50) NULL, 
     [Title]   NVARCHAR (50) NULL, 
     [Username]  NVARCHAR (50) NULL, 
     CONSTRAINT [PK_TeacherDetails] PRIMARY KEY CLUSTERED ([TeacherId] ASC) 
    ); 

我會如此很感激,如果有人可以幫助我解決我的問題,如果是的話,我使用嘗試插入記錄代碼那麼請不要使用非常複雜的措辭,因爲我是一個編碼新手。

托馬斯

+0

您正在嘗試連接並使用SQL Server實例,並且出現錯誤 - 您使用的服務器/實例名稱是錯誤的(可能是拼寫錯誤?),或者它不存在,或者它不可訪問,或者它沒有配置爲遠程連接(對於SQL Server Express) – 2015-04-02 13:03:00

回答

0

嘗試連接VS于斌/調試,您正在運行你的應用程序的.mdf文件 因爲根據錯誤要麼你用不上,或者它是不是能找到.mdf文件。

+0

我該怎麼做?我可以在調試欄中看到「Attach to Process」,但是我似乎只能攻擊已經打開的文件,並且無法打開.mdf文件。 – mot375 2015-04-02 14:52:54

+0

我在說你的.mdf文件的bin \ debug文件夾有你的.mdf – 2015-04-02 15:46:55

+0

我在說你的項目的bin \ debug文件夾出你的.mdf那裏。嘗試放在其他驅動器,而不是C它會更好。 – 2015-04-02 16:08:29