无法导出为XML

3

我有一个与我的网站连接的名为Sort.sdf的SQL Compact数据库,其中包含一个名为“sort”的表。我需要将表中所有记录导出到XML文件,但我一直遇到以下错误,无法找到解决方法:

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: Named 
Pipes Provider, error: 40 - Could not open a connection to 
SQL Server)

我已经使用相同的连接成功地向数据库中插入了数据,所以我认为那里没有问题。

SqlCeConnection conn = new SqlCeConnection("Data Source=|DataDirectory|Sort.sdf");
conn.Open();

DataSet ds = new DataSet();
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("Select * from Sort", conn.ConnectionString);
da.Fill(ds); //error on this line

ds.WriteXml(@"c:\temp\output.xml", XmlWriteMode.WriteSchema);

2
你需要一个 SqlCeDataAdapter。这里从未使用过 conn - H H
问题已解决,谢谢 :) - Moffatt
1个回答

0
SqlCeConnection cnn = new SqlCeConnection("Data Source=|DataDirectory|Sort.sdf");
cnn.Open();
SqlCommand cmd = new SqlCommand("select * from  sort", cnn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds);

StreamWriter xmldoc=new StreamWriter(Server.MapPath("~/Testdo.xml"), false); 
ds.WriteXml(xmldoc);
xmldoc.Close();

你对那段代码有什么问题?请查看你的应用存储区,它会自动生成。 - user3345611

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接