草庐IT

SqlCeConnection

全部标签

c# - 无法导出为 XML

我有一个名为Sort.sdf的sqlcompact数据库连接到我的网站,其中有一个名为“sort”的表。我需要将表中的所有记录导出到一个XML文件,但我不断收到以下错误并且找不到解决方案:Anetwork-relatedorinstance-specificerroroccurredwhileestablishingaconnectiontoSQLServer.Theserverwasnotfoundorwasnotaccessible.VerifythattheinstancenameiscorrectandthatSQLServerisconfiguredtoallowremote

c# - 发生异常时关闭数据库连接的正确方法

如果出现异常,以下代码是否使连接保持打开状态?我使用的是MicrosoftSQL精简版数据库。try{SqlCeConnectionconn=newSqlCeConnection(ConnectionString);conn.Open();using(SqlCeCommandcmd=newSqlCeCommand("SELECTstuffFROMSomeTable",conn)){//dosomestuff}conn.Close();}catch(Exceptionex){ExceptionManager.HandleException(ex);}当然更好的方法是在try之前声明一个连