Click here to Skip to main content
15,868,340 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to SQL. Any veterans want to assist?

I want to get connected to sample database named codeproject.sdf from C# application.

I used following connection string:
string source=@"Data source=C:\codeproject.sdf"

The file was in the location specified but whenever I execute the program I get the following error:

A network-related or instance-specific error occured 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 not configured to allow remote connections. (provider:SQL network Interfaces, error: 26 - Error locating Server/Instance Specified)

Thanks!
Posted

You probably need to be running SQL Server for Windows CE and SQL Server Mobile Edition to access this file.
 
Share this answer
 
v2
Comments
Nish Nishant 18-Jan-11 13:57pm    
Ah thanks, didn't catch that. Updated my reply.
Nish Nishant 18-Jan-11 13:57pm    
Voted 5.
Abhinav S 18-Jan-11 13:59pm    
Thanks Nish.
You need to use a proper connection string.

See http://www.connectionstrings.com/sql-server-2008[^]

That link's for SQL Server 2008 but you should be able to find one that matches your version.

After seeing Abhinav's response, here's a page that lists suitable connection strings for SQL Srver CE:

http://www.connectionstrings.com/sql-server-2005-ce[^]
 
Share this answer
 
v2
Comments
Espen Harlinn 18-Jan-11 14:45pm    
5+ Nice addition
zachary k stenger 18-Jan-11 15:10pm    
Thanks Nishant!
Nish Nishant 18-Jan-11 15:11pm    
You're welcome.
To access a .SDF file you do not need to use SQL server at all, SqlCE support is built into .NET
Just add a reference to the System.Data.SqlServerCe namespace and a using System.Data.SqlServerCe; to your code.
You then access the database via the SqlCeConnection and SqlCeCommand classes. There is a walkthrough here: MSDN[^]
 
Share this answer
 
Comments
Espen Harlinn 18-Jan-11 14:46pm    
5+ Probably a link he will find quite useful
zachary k stenger 18-Jan-11 15:10pm    
Thank you OriginalGriff. I am good to go.
fjdiewornncalwe 18-Jan-11 15:14pm    
My vote for the best answer on this one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900