2

I keep getting an error while trying to connect my asp.net project to sql ce 4.

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible."

UPDATE - If you are getting this error make sure you specify the proper provider name in both the connection string and the sqldatasource.

providerName = "System.Data.SqlServerCe.4.0"

How connect to SQL Server Compact 4.0 in ASP.NET?

1
  • 1
    Is the update supposed to be the solution for your problem? Commented Sep 7, 2011 at 15:41

2 Answers 2

0

It's also worth knowing that you need to ensure a correct provider name if you wish to use the 'GetFactory' methods on a connection string to decouple your db connection code from your business logic.

0

I had the problem too, because I switched from SQL Server Express to SQL Server Compact 4.0. My code:

            SqlDataSource SqlDataSource2 = new SqlDataSource();
            SqlDataSource2.ID = "SqlDataSource2";
            SqlDataSource2.ConnectionString = @"Data Source=|DataDirectory|\database.sdf;Password=passwordddddDDD;Persist Security Info=False;";
            SqlDataSource2.SelectCommand = "SELECT * FROM [table1]";
            SqlDataSource2.ProviderName = "System.Data.SqlServerCe.4.0"; // THIS line solved my problem!
            GridView1.DataSource = SqlDataSource2;

Thank you, this helped me a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.