2
我有一個SQL壓縮數據庫連接到我的網站Sort.sdf
,有一個名爲「排序」的表。我需要從表中的所有記錄導出到一個XML文件,但我不斷收到以下錯誤,無法找到一個解決方案:無法導出到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'在這裏永遠不會被使用。 –
謝謝您解決的問題:) – Moffatt