Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET2.0 C# SQL
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 14-Jan-11 3:07am
Edited 14-Jan-11 4:15am
v2
Comments
OriginalGriff at 14-Jan-11 9:50am
   
Answer updated - forgot to say when I did it...
Dalek Dave at 14-Jan-11 10:15am
   
Edited for Readability.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
v3
Comments
Shah Rukh Qasim at 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 at 14-Jan-11 10:15am
   
Good Call, Griff.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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."
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 239
1 Sarvesh Kumar Gupta 185
2 George Jonsson 154
3 ArunRajendra 144
4 Richard MacCutchan 140


Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid