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 4599888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:36:21+00:00 2026-05-21T23:36:21+00:00

I have database in file C:\Users\Pawel\Documents\DB.sdf . How can I connect to it? Simple

  • 0

I have database in file C:\Users\Pawel\Documents\DB.sdf. How can I connect to it?

Simple code below does not work and generates exception.

Code:

[WebMethod]
public String TestCon()
{
    SqlConnection sql = new System.Data.SqlClient.SqlConnection(
        @"Data Source=C:\Users\Pawel\Documents\DB.sdf");

    string str = "OK";

    try
    {
        sql.Open();
        sql.Close();
    }
    catch (Exception ex)
    {
        str = ex.Message;
    }

    return str;
}

Result:
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)

What am I missing? What I should do to open connection correctly?

EDIT:
System.NotSupportedException: SQL Server Compact is not intended for ASP.NET development.
Great 😛

  • 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-05-21T23:36:21+00:00Added an answer on May 21, 2026 at 11:36 pm

    Consider using System.Data.SqlServerCe.SqlCeConnection:

    System.Data.SqlServerCe.SqlCeConnection con = 
       new System.Data.SqlServerCe.SqlCeConnection(@"Data Source=C:\Users\Pawel\Documents\DB.sdf");
    

    (Add a reference to System.Data.SqlServerCe, if necessary)

    Also, to use it with ASP.NET, add:

    AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a db2 database file, but do not have a db2 server. I
I am implementing a very simple file database. I have 2 basic operations: void
I have a webpage where users can create a database record and select a
I have a pretty simple HTML form where users can enter in information about
I have to find a suitable location to deploy my SDF (database) file. The
I have a database file that is generated on a PC using Sqlite. This
I have a *.MDB database file, and I am wondering if it is possible
I have an Oracle database backup file (.dmp) that was created with expdp .
Is there a way to have an application access a SQL Compact database file
Sorry the title isn't more help. I have a database of media-file URLs that

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.