Hi I\'m trying to connect an SQL server compact database to my program and I want a button that deletes all entries from the database, when I Press said button the program t
You seems to be using a bad connection string. (Or the file path is wrong). Check out http://www.connectionstrings.com/sql-server-ce for connection string options.
Try use SqlCeConnection
class rather than SqlConnection
:
SqlCeConnection sqlConnection1 = new SqlCeConnection();
sqlConnection1.ConnectionString = "Data Source = C:\\Users\\Administrator\\My Documents\\BMS_Data.sdf;Persist Security Info=False";
If you want to connect to SQL Server Compact, use SqlCeConnection, SqlCeCommand etc. Add a reference to the SQL Server Compact ADO.NET provider, System.Data.SqlServerCe.dll
Have a look at this blog article: SQL SERVER – FIX : ERROR : (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)
This goes step-by-step through what you might need to do:
In short:
- SQL Server should be up and running.
- Enable TCP/IP in SQL Server Configuration
- Open Port in Windows Firewall
- Enable Remote Connection
- Enable SQL Server Browser Service
- Create exception of sqlbrowser.exe in Firewall
- Recreate Alias
About the where and what to do in each step, you will find more in-depth information in the article.
You may also want to have a look at the Connection strings for SQL Server Compact. There you can find other variations of the connection string you could try to play with.