Working with SQL Server 2010 in VC# 2010

[Edit: so much for my first attempt at posting something useful! When I first wrote this post, I had resigned myself to the fact that C# in VS2012 Express was only going to be available for Windows 8. Now VS Express for Desktop is available for Windows 7 and both the Database Explorer and graphical EDMX creator solve the problem outlined below! For anyone with the problem of not being able to connect to SQL Server 2012 in VS2010 Express, my advice would now be to upgrade to VS2012.]

I came across a problem (and solution!) that intrigued me recently in Visual Studio 2010. I thought I’d share it in case anyone else found the same thing.

I have recently got back in to C# programming – there’s now a good reason to because I need a particular piece of bespoke software for my business. I’m using Windows 7 with Visual Studio 2010 Express Edition – I’m a hobby programmer after all! I have also recently acquired SQL Server 2012 Express Edition. My intention is to create an Entity Framework-based class library backend, initially with a WPF/C# frontend (although one of the reasons for keeping the two items separate from an early stage, is that I would ultimately like to access the database through Silverlight too).

Here’s the situation: Install Visual C# 2010 + SP1 – fine. Install SQL Server 2012 – fine. Create a class library project and add and “ADO.NET Entity Data Model”, generated from a database…but which data connection should I choose? I appear to have only 2 options, namely “Microsoft SQL Server Compact 3.5″ and “Microsoft SQL Server Database File”. Hmm. Not what I wanted, but OK – we can probably get away with the second option. It’s always possible to change the connection string to “properly” use SQL Server later:

Change Data Source Dialog Box

Visual C# 2010 Change Data Source Dialog Box

We’re then asked to select the database file to use. We can either point to an existing database file or create a new one. In my case, I had created a basic outline database in SQL Server Management Studio. Problem is, when we select this file (located using the database path location initially specified when installing SQL Server), we get an error that the file is in use and cannot proceed. I’ve tried fiddling with file and directory permissions, but to no avail.

OK – next port of call was to create a new database and edit it using the Database Explorer. Annoying, but surely workable. It turns out that this assumption was wrong.

Visual C# 2010 Entity Data Model Wizard Dialog Box

The Visual C# 2010 Entity Data Model Wizard Dialog Box – all seems well so far…

Server Not Supported Error

…but then!

Page 1 of 2 | Next page