连接到本地SQL Server CE数据库时出错

时间:2015-06-28 03:26:47

标签: c# database sql-server-ce

//SqlCeConnection con = new SqlCeConnection( "Data Source=" + System.IO.Path.Combine( Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location ), "DBThree.sdf" ) );

//SqlCeConnection con = new SqlCeConnection( @"Data Source=|DataDirectory|\DBThree.sdf" );

//SqlCeConnection con = new SqlCeConnection( ConfigurationManager.ConnectionStrings["DBThreeConnectionString"].ConnectionString );

SqlCeConnection con = new SqlCeConnection( @"Data Source=""C:\Users\Visual Studio 2012\Projects\ForTesting2\ForTesting2\DBThree.sdf""" ); 
con.Open();

string comnd = "SELECT COUNT (*) FROM Mytable";
SqlCeCommand com1 = new SqlCeCommand( comnd, con );

string test1 = com1.ExecuteScalar().ToString() ;
label1.Text = "AAA\t" + test1;
con.Close();

我收到以下错误:

  

System.Data.SqlServerCe.SqlCeException(0x80004005):解析查询时出错。 [令牌行号= 1,令牌行偏移= 23,令牌错误= Mytable]

我还尝试了上面代码中注释的连接字符串。 app.config中的连接字符串类似于

<connectionStrings>
    <add name="DBThreeConnectionString"
         connectionString="Data Source=|DataDirectory|\DBThree.sdf"
         providerName="Microsoft.SqlServerCe.Client.4.0" />
</connectionStrings>

0 个答案:

没有答案