CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    11

    Question Problems connecting to SQL database with LINQ

    Hi Hivemind,

    I'm working through a textbook example of using LINQ with a SQL database. I'm using Visual C# Express 2008, Microsoft SQL Server 2005 Express and Microsoft SQL Server Management Studio 2005 Express. I'm working on a sample database AdventureWorksLT which is provided by Microsoft here:

    http://www.codeplex.com/MSFTDBProdSa...ReleaseId=4004

    It's the AdventureWorksLT.msi version that I'm using. After Installing SQL Server 2005 I've then gone into "Configuration Tools > SQL Server Configuration Manager" in the Vista start menu, then selected "SQL Server 2005 Network Configuration > Protocols for SQLEXPRESS" and set "Named Pipes" to Enabled. I've then restarted the "SQL Server (SQLEXPRESS)" entry in the "SQL Server 2005 Services" panel.

    I've then started SQL Server Management Studio in administrator mode and connected to the server. I've right-clicked "Databases" in the left panel, selected "Attach..." and attached the AdventureWorksLT database. The database now shows in the Databases folder under the "System Databases" folder.

    I've then started Visual C# Express 2008 in administrator mode and created a new console application. In the "Database Explorer" window I've right-clicked "Data Connections" and then selected "Add Connection". In the "Database file name" text box I've selected the "AdventureWorksLT_Data.mdf" file which is in "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data".

    When I click the "Test Connection" button I then get an error dialog with the message "Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed".

    What is causing this? Have I somehow installed SQL Server 2005 incorrectly? This is my first attempt at using LINQ with SQL and I've followed all the steps in the textbook.

    Thanks

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Problems connecting to SQL database with LINQ

    Not sure why you've enabled named pipes - AFAIK, it's an older protocol that's not required any longer.

    If you've attached the the database to your SQL Express instance, then you don't need to attach to the database by file name.

    Instead, just select "Microsoft SQL Server" and press continue. Choose the machine and server instance (e.g. MYMACHINE\SqlExpress) and select the database.

  3. #3
    Join Date
    Jun 2009
    Posts
    11

    Question Re: Problems connecting to SQL database with LINQ

    Quote Originally Posted by Arjay View Post
    Not sure why you've enabled named pipes - AFAIK, it's an older protocol that's not required any longer.

    If you've attached the the database to your SQL Express instance, then you don't need to attach to the database by file name.

    Instead, just select "Microsoft SQL Server" and press continue. Choose the machine and server instance (e.g. MYMACHINE\SqlExpress) and select the database.
    I've tried disabling Named Pipes and the error message is still the same.

    In relation to the rest of your advice, I think this is what I have done. I've right-clicked "Data Connections" in the "Database Explorer" panel in Visual C# 2008 Express and selected "Add Connection". This opens up a dialog window with the title "Add Connection".

    Within this window are two text fields with the titles "Data source" and "Database file name (new or existing)". Within the first of these is the entry "Microsoft SQL Server Database File (SqlClient)". This is the only option I have to enter for this. Within the second text field I've then selected "AdventureWorksLT_Data.mdf". I then get the error when I click the "Test Connection" button.

    Towards the bottom of the window is an "Advanced" button which opens up an "Advanced Properties" dialog. Is there some setting in there I can change to overcome the error?

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured