C# 无法导出为XML
我有一个sql compact数据库连接到我的网站,名为C# 无法导出为XML,c#,asp.net,sql,xml,C#,Asp.net,Sql,Xml,我有一个sql compact数据库连接到我的网站,名为Sort.sdf,还有一个名为“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. Ve
Sort.sdf
,还有一个名为“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);
您需要一个SqlCeDataAdapter
conn
从未在此处使用。谢谢。问题已解决:)您对该代码有什么问题?查看您的应用程序存储区域,它将在那里生成
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();