如何将windows CE c#应用程序连接到数据库SQL Server2008r2

问题描述:

请帮忙。 我有设备MC3200 Zebra(摩托罗拉)(Windows Embedded版本7,版本2864)。该设备正在连接到网络并查看SQL服务器(ping可以)。我用它的Visual Studio 2008,C#,SmartDevicePrj,.NET CF 3.5如何将windows CE c#应用程序连接到数据库SQL Server2008r2

enter image description here

但之后在设备上启动应用程序将显示消息:

在连接字符串中未知的连接选项:初始目录。

一些想法如何修复它?

非常感谢您的帮助。

using System; 
    using System.Linq; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Text; 
    using System.Windows.Forms; 
    using System.Data.SqlServerCe; 

namespace SmartDeviceProject1 
{ 
    public partial class Form1 : Form 
    { 
     public SqlCeConnection msConn; 
     public string strCon = ""; 
     public SqlCeCommand command; 

     public Form1() 
     { 
      InitializeComponent(); 
      strCon = "Data Source=server007; Initial Catalog=FMPredlis; User ID=mistr; Password=heslo;"; 
      try 
      { 
       msConn = new SqlCeConnection(strCon); 
       msConn.Open(); 
       MessageBox.Show("Připojeno"); 
      } 
      catch (SqlCeException ex) 
      { 
       MessageBox.Show("Chyba" + ex.Message); 
       msConn.Close(); 
      } 
     } 
    } 
} 
+0

确定Windows CE设备可以查找名为“server007”的名字? – BugFinder

+0

IIRC,SqlCeConnections被指定为“Data Source = MyData.sdf”,根本无法连接到“真实”SQL服务器。 – dlatikay

我想你是混合2件事。

要么使用SqlConnection对象,那么你可以使用此页面上发现了一个连接字符串连接到SQL Server: https://www.connectionstrings.com/sql-server/

或者在代码中的SqlCeConnection使用像,那么你连接到SQL精简版(本地文件),你的连接字符串应该像这个页面上: https://www.connectionstrings.com/sqlite/

但在你的示例中,你正在使用SqlCEConnection连接到一个sql服务器,这将无法正常工作。

Grtz

+0

是的,我其实混合了两件事。在项目开始时,我遇到了一个System.Data.SqlClient引用的问题,所以我走开了。 现在一切正常。我仍然有一个dbnetlib.dll的问题,但我已经解决了它通过https://*.com/questions/21838161/cant-find-pinvoke-dll-dbnetlib-dll-error-in-smart-device-application 非常感谢您的帮助! –