0

I'm not a very experienced programmer and am currently using Microsoft Visual Studio Express 2013 for Windows Desktop for my coursework project.

I am currently trying to add a new record (I think it's called a record, I mean row) to my TeacherDetails table using LINQ to SQL however whenever I click on button2 an error comes up saying :

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)

(Which I'm not really sure means)

Whenever I press continue and try refresh my table/ database another error appears saying:

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

This is the code that I am using to try and insert the record:

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 = "smckay@email.co.uk";
        cust.Title = "Mr";
        db.TeacherDetails.InsertOnSubmit(cust);


         db.SubmitChanges();


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

This is my database code thingy:

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)
    );

I would be so very grateful if someone could help me solve my problem if so then please don't use very complex wording because I'm a bit of a coding newbie.

Thomas

Community
  • 1
  • 1
mot375
  • 99
  • 1
  • 13
  • You're trying to connect to and use a SQL Server instance, and you're getting something wrong - either that server/instance name you're using is wrong (maybe a typo?) or it doesn't exist, or it's not reachable, or it's not configured for remote connections (for SQL Server Express) – marc_s Apr 02 '15 at 13:03

1 Answers1

0

Try attaching VS to the .mdf file in bin/debug where you're running your app because according to the error either you don't have access or it is not able to find the .mdf file.

Rahul Sharma
  • 453
  • 3
  • 10
  • How can I do that? I can see "Attach to Process" under the debug bar however I can only seem to attack files that are already open and I cannot open a .mdf file – mot375 Apr 02 '15 at 14:52
  • I am saying about bin\debug folder for your project out your .mdf there – Rahul Sharma Apr 02 '15 at 15:46
  • I am saying about bin\debug folder for your project out your .mdf there. try put In some other drive instead of C it will be better. – Rahul Sharma Apr 02 '15 at 16:08
  • My ProjectDB.mdf is already in that folder if that's what you meant – mot375 Apr 02 '15 at 16:56