将数据库从基于服务的数据库传输到本地数据库时出错

时间:2013-01-28 13:48:40

标签: c# sql-server

我刚刚知道基于服务的数据库和本地数据库之间的差异,所以根据我的需要,我已经将项目数据库转移到本地数据库,我已经质疑并发现我只需要替换连接字符串,这是主要的在那里的东西,没有什么我必须在我的代码中添加和替换所以。现在我得到的错误,我不知道如何解决 我的本地数据库代码是

       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)

1 个答案:

答案 0 :(得分:1)

您必须使用SqlCeConnectionSqlCeCommand代替SqlConnectionSqlCommand

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