Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get connected to sample database named Northwind.sdf from C# application. I used following connection string:
string source=@"Data source=C:\Northwind.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)


Can anyone tell me how to solve the problem?

I am new to SQL.

Thanks in advance.
Posted
Updated 14-Jan-11 4:15am
v2
Comments
OriginalGriff 14-Jan-11 9:50am    
Answer updated - forgot to say when I did it...
Dalek Dave 14-Jan-11 10:15am    
Edited for Readability.

An SDF file will most likely (in this case) be and SqlCE file, rather than an SQL file. This is a stand alone database that does not use SQL server.

Instead, use the SqlCEConnection and SqlCECommand Classes and you should be fine. You will need to reference the System.Data.SqlServerCe assembly (in system.data.sqlserverce.dll).
See MSDN[^] for more details.

[edit]Typos - OriginalGriff[/edit]

"Thanks a lot for your answer. It worked perfectly fine. OK can you please tell me that can the SqlCEConnection can do all things that SqlConnection can? - Shah Rukh Qasim 6 mins ago"


It can do pretty much everything (a good description is here[^]). The main difference is that it is single user rather than multiuser and intended for standalone applications.
SQLServer can read these (but it can be a pain to do sometimes in my experience). There is a query tool here: SQL Server CE Query Tool[^] which is a little less painful.

It's handy to have, the syntax is the same etc., just you don't need SQL Server installed because the .NET assembly handles it all internally. This can make distribution easier, and be a lot more flexible than using XML data files sometimes!
 
Share this answer
 
v3
Comments
Shah Rukh Qasim 14-Jan-11 9:23am    
Thanks a lot for your answer. It worked perfectly fine. OK can you please tell me that can the SqlCEConnection can do all things that SqlConnection can?
Dalek Dave 14-Jan-11 10:15am    
Good Call, Griff.
See this[^] -

"Important If you are using Windows Vista, you cannot connect to the Northwind.sdf if Visual Studio is running in a non-administrator mode. To make a connection to Northwind.sdf, the database file should not be in Windows directory, Program Files directory, or system drive. It should be in a user directory or some other drive. To connect to the Northwind.sdf, start Visual Studio in the Run as administrator mode."
 
Share this answer
 
i see that you're programming using sdf files.
do you know about .sdf files? its use for databases. i am going to make a sdf viewer but i dont know where to start. can you help me?
i need to make a sdf viewer application using vb.net (window-based)
 
Share this answer
 

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