1

我刚刚知道基于服务的数据库和本地数据库之间的差异,因此根据我的需要,我已将项目数据库转移到本地数据库,我质疑并发现我只需要替换连接字符串,这是其中的主要内容我不需要在我的代码中添加和替换任何东西。现在我收到了我不知道如何解决本地数据库代码的错误

       SqlConnection con = new SqlConnection();
              SqlConnection conn = new SqlConnection();
              conn.ConnectionString = @"Data Source=E
    :\project\+project\WindowsFormsApplication1\Database1.sdf";
              SqlCommand cmd = new SqlCommand();
              cmd.Connection = conn;
              conn.Open();
              try
         {
             // something
          }

              catch (Exception)
          {
              MessageBox.Show("ERROR");

          }
              conn.Close();
          }

我在 conn.open 上遇到错误

 A network-related or instance-specific error occurred 
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 configured 
to allow remote connections. (provider: SQL Network Interfaces,
 error: 26 - Error Locating Server/Instance Specified)
4

1 回答 1

1

您必须使用SqlCeConnectionandSqlCeCommand而不是SqlConnectionand SqlCommand

示例:http : //www.dotnetperls.com/sqlce

于 2013-01-28T13:56:13.343 回答