Click here to Skip to main content
15,560,073 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have error in the connection to Sql server in C# program

this is the code of connection
SqlConnection connection = new SqlConnection();
connection.ConnectionString = 
@"Data Source=D:\NewCode\DataBaseWin.sdf;Integrated Security=SSPI";

and this is the error
provider sql network interfaces error 26 - error locating server/instance specified

what I have to do ?

1 solution

Why are you using an SqlConnection to connect to an SDF file? Why not use an SqlCeConnection?
SqlCeConnection connection = new SqlCeConnection();
connection.ConnectionString = 
@"Data Source=D:\NewCode\DataBaseWin.sdf;Integrated Security=SSPI";
Share this answer
maxpower12345 7-May-12 14:18pm    
What is the differences between SqlConnection and SqlCeConnection ?
OriginalGriff 7-May-12 14:30pm    
SqlConnection is intended to connect to databases managed by SQL Server - these are not normally referred to by an extension as the SQL server instance takes care of that (and a lot of other things) behind the scenes. These are generally multiuser (or you are downloading a lot of software for no real benefit).
SqlCeConnection connects only to .SDF files and works with them in a single user environment.

If yopu connect with SqlConnection, you must use SqlCommand and related objects, if you connect with SqlCeConnection, you use SqlCeComamnd and related objects instead.

Not trying to be rude, but why are you using an .SDF file if you don't know this?
maxpower12345 7-May-12 14:46pm    
:$ Actually I thought its not diffident from mdf
:S oops
OriginalGriff 7-May-12 14:56pm    
Nah, SDF is single user stuff created originally for WinCE devices - it's handy though, for well structured datafiles if you want to be able to work in a record based manner without having to re-write the file each time you insert or delete.
It also has a small footprint - the files needed to run it are tiny compared to MSSQL!
maxpower12345 7-May-12 15:33pm    
Great >> so I have to make new database (mdf)
thanks for your help
I hope if make mdf will help to solve the error

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