views:

4623

answers:

5

Hi guys, I have a problem with Visual C# 2008 express (SP1) connecting to SQL Server 2008 express. The "Add Connection" window (wherever initiated) doesn't list existing sql server and no option for sql server except a compact edition.

Note that, I've got the VWD 2008 express (SP1) on the same machine which shows the window regularly (with SQL server listed) and SQL Server Management studio works fine with the server as well.

I've seen other similar posts, did take some advices: reinstalled the VC#, services run ok, etc... but with no success with VC# so far.

Again, on the same machine the VWD shows the dialog with sql server option regularly, but VC# shows only 3 options in "Change data source" dialog (1. Microsoft Access Database File (OLE DB) 2. Microsoft SQL Server Compact 3.5, 3. Microsoft SQL Server Database File)

Any idea? Thanks in advice, Phil

+1  A: 

SQL 2005 and SQL 2008 Express Editions install themselves as Named Instances.

You should be able to enter ".\SQLEXPRESS" to connect.
The "." is a shortcut for "localhost", and the "SQLEXPRESS" is the Instance Name for SQL Express.

You can verify the instance name in your Services control panel:

  • Start -> Run -> services.msc
  • Scroll down to SQL Server
  • The Instance Name should be in brackets. eg: "SQL Server (SQLEXPRESS)"
Will Hughes
Will, thanks for the quick response,unfortunately, everything is fine with the server (I checked it out earlier), but looks like something's wrong with the VC#.I also tried to use many variations in Advanced window settings, including .\SQLEXPRESS, MYHOSTNAME\SQLEXPRESS...:(
Ah, in that case -- have you checked that you can connect using the sqlcmd tools too? eg: C:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd -S .\SQLEXPRESS
Will Hughes
Yes, I do, with no problem
A: 

You described option 3 - Microsoft SQL Server Database File, you should be able to use this to point to your .mdf file and it will be able to connect just from this.

Cookey
Hi Cookey, thanks for the responseI'm able to point to .mdf file, but I would like (for some reason) to use connection to the server the same way as I do with VWD, if possible.
A: 

I've got the same problem!! I don't know what it is but i can point it to a .mdf file but i would like to have it connected to the live database... If you find a solution let me know ... I haven't tried uninstalling C# with no luck... Going to try SQL next . Will let you know if it works!

Craig
+2  A: 

I am with Phil on this Visual Web Developer 2008 Express Tools>Connect to Database... brings up Add Connection dialog with Server name:

Visual C# 2008 Express has Database file name (new or existing):

This rather implies using ado.net programatically

as in SqlConnection db = new SqlConnection(); db.ConnectionString= ...

"Data Source=.\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=True; providerName=System.Data.SqlClient";

[Data Source=server\SQLEXPRESS] I seem to have ASPNETDB.MDF files that have been created in my project areas but do not confuse these with

C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\master.mdf

MVS.NET 2003 required Microsoft SQL Server 2000 Desktop Engine ontop of SQL Server 2000. It all rather reminds me of using Microsoft Access to Attach to SQL Server via ODBC as a means of getting 'bound controls' in Access Basic.

Rat1960
A: 

Could it be that the express product won't let you connect in the normal way because it qualifies as 'remote'?

A bit of Chinglish but see the table in the response: http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/51df3937-1f24-4131-80d6-486552660bad

I'm having the same problem.

justin w