由于我使用的操作系统是windows server 2003,
不能安装win ce 5.0的模拟器,而vs2005没有自带的win ce 模拟器,
现在已经安装了sql ce 3.0,想使用vs2003连接sql ce 3.0,但出现如下错误:
代码如下(网上的例子):
public void ShowErrors(SqlCeException e)
{
SqlCeErrorCollection errorCollection = e.Errors;
StringBuilder bld = new StringBuilder();
Exception inner = e.InnerException;
if (inner != null)
{
MessageBox.Show(("Inner Exception: " + inner.ToString()));
}
foreach (SqlCeError err in errorCollection)
{
bld.Append("\n" + " Error Code: " + err.HResult.ToString());
bld.Append("\n" + " Message : " + err.Message);
bld.Append("\n" + " Minor Err.: " + err.NativeError);
bld.Append("\n" + " Source : " + err.Source);
foreach (int numPar in err.NumericErrorParameters)
{
if (0 != numPar)
{
bld.Append("\n" + " Num. Par. : " + numPar);
}
}
foreach (string errPar in err.ErrorParameters)
{
if (string.Empty != errPar)
{
bld.Append("\n" + " Err. Par. : " + errPar);
}
}
MessageBox.Show(bld.ToString());
bld.Remove(0, bld.Length);
}
}
private void button1_Click(object sender, System.EventArgs e)
{
//SQL CE
SqlCeConnection conn = null;
try
{
if (File.Exists("Test.sdf"))
File.Delete("Test.sdf");
SqlCeEngine engine = new SqlCeEngine("Data Source = Test.sdf");
engine.CreateDatabase();
SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess();
rda.InternetUrl = "http://***/sqlce/sqlcesa30.dll";
rda.InternetLogin = "IUSER_***";
rda.InternetPassword = "1";
rda.LocalConnectionString = "Data Source=Test.sdf";
conn = new SqlCeConnection("Data Source = Test.sdf");
conn.Open();
rda.Pull("bcjh","SELECT top 10 bcrq,bch FROM bcjh","Provider=sqloledb;server=***;database=****;uid=***;pwd=***;",RdaTrackOption.TrackingOnWithIndexes,"ErrorTable");
String SqlSelect = "SELECT bcrq,bch FROM bcjh";
SqlDataAdapter objAdapter = new SqlDataAdapter(SqlSelect, "Data Source = Test.sdf");
DataSet objDataSet = new DataSet();
objAdapter.Fill(objDataSet, "dt");
dataGrid1.DataSource = objDataSet.Tables["dt"];
dataGrid1.Refresh();
}
catch (SqlCeException ex)
{
// MessageBox.Show("aaaa");
ShowErrors(ex);
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}
错误:
ERROR CODE:-2147467259
Message:SQL Server CE Encountered problems in opening the SQL Server
CE database.[,,,Database Name,,]
Minor Err:28559
Source : Microsoft SQL Server 2000 Windows CE Edition
(前提:SQL CE 3.0 安装正确,在vs2005的 ppc模拟器连接是正常的,使用的是SqlCeDataAdapter)
谢谢!
ERROR CODE:-2147467259
Message: There is a file sharing violation. A different process might be using
the file [,,,,,]
Minor Err:25035
Source : Microsoft SQL Server 2000 Windows CE Edition