Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9057423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:27:05+00:00 2026-06-16T14:27:05+00:00

I am creating in Visual Studio Express 2012 for web simple CRUD web application

  • 0

I am creating in Visual Studio Express 2012 for web simple CRUD web application (library) as school project. I am inspired by this very nice tutorial – http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-1

Now I have problem with connection to a SQL Server Compact edition .sdf data file.

In web.config I have this connection string:

<connectionStrings>
    <add name="LibraryEntities"
     connectionString="Data Source=C:\Users\Administrator\Documents\Visual Studio 2012\Projects\2OBOP3_KU1\R10491\App_Data\R10491_library.sdf;"
     providerName="System.Data.SqlServerCe.4.0"/>
  </connectionStrings>

I created simple ASPX file for database connection testing:

<script runat="server">
  protected void Page_Load(object sender, EventArgs e)
  {
      using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["LibraryEntities"].ToString()))
      {
          SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM Writers", cn);
          cn.Open();
          SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
          rdr.Read();
          Response.Write(rdr[0].ToString()); //read a value
      }
  }
</script>

When I run an application it throws an exception:

Exception Details: System.Data.SqlClient.SqlException: 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)

But when I try to connect to my .sdf file in “Database explorer” tab in “Database Explorer” menu (next to “Solution explorer”) I connect successfully.

So I assuming there should be a problem in connection string – isn’t it? Thank you for your advices.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:27:06+00:00Added an answer on June 16, 2026 at 2:27 pm

    You are connecting to a SQL Server Compact not to SQL Server.

    You should use SqlCeConnection not SqlConnection.

      using System.Data.SqlServerCe;
    
      protected void Page_Load(object sender, EventArgs e)
      {
          using (SqlCeConnection cn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["LibraryEntities"].ToString()))
          {
              SqlCeCommand cmd = new SqlCeCommand("SELECT COUNT(*) FROM Writers", cn);
              cn.Open();
              SqlCeDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
              rdr.Read();
              Response.Write(rdr[0].ToString()); //read a value
          }
      }
    

    also you need to have a reference to system.data.sqlserverce.dll

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a simple C++ DLL project using Visual Studio 2008 Express Edition.
I have just finished creating a wpf application in visual studio express C# and
I am creating a Visual Studio 2010 Setup project for installing my application. My
I am using Visual Studio 2008 Express and I tried creating a simple console
When creating a Portable Class Library in either Visual Studio 2010, or Visual Studio
when i am creating new android project from visual studio 2010 it gives the
I am creating an azure package using Visual Studio (right click on azure project
I am creating a .NET form application in Visual Studio 9. In the designer
When creating a new WSPBuilder project or new WSPBuilder item in Visual Studio, you
Taken from Exercise 1: Creating Windows Phone Applications with Microsoft Visual Studio 2010 Express

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.