Connecting C# to SQL Server Compact database

前端 未结 4 1915
暖寄归人
暖寄归人 2021-01-19 00:11

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

相关标签:
4条回答
  • 2021-01-19 00:51

    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.

    0 讨论(0)
  • 2021-01-19 00:52

    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";
    
    0 讨论(0)
  • 2021-01-19 00:55

    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

    0 讨论(0)
  • 2021-01-19 01:00

    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:

    1. SQL Server should be up and running.
    2. Enable TCP/IP in SQL Server Configuration
    3. Open Port in Windows Firewall
    4. Enable Remote Connection
    5. Enable SQL Server Browser Service
    6. Create exception of sqlbrowser.exe in Firewall
    7. 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.

    0 讨论(0)
提交回复
热议问题