【求助】,把代码拷贝到另一台电脑后,报错,无法解决
连接的数据库是 Server Compact 3.5,从办公室把代码拷贝到笔记本后,提示错误,无法运行,但是在办公室电脑运行却没问题报错提示是“找不到数据库文件。请检查数据库的路径。 [ Data Source = systemDb.sdf ]”
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.Configuration;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
/* FolderBrowserDialog dlg = new FolderBrowserDialog();
if (dlg.ShowDialog() != DialogResult.OK)
{
return;
}
string path = dlg.SelectedPath;
OpenFileDialog ofd = new OpenFileDialog();
if(ofd.ShowDialog()!=DialogResult.OK)
{
return;
}
*/
String commStr = ConfigurationManager.ConnectionStrings["CommStr"].ConnectionString; //需要去添加引用
using (SqlCeConnection comm = new SqlCeConnection(commStr))
{
comm.Open();
using (SqlCeCommand cmd = comm.CreateCommand())
{
= "select * from TBLSYS_PINYIN";
using (SqlCeDataReader dataReader =cmd.ExecuteReader()) //对数据库进行逐行读取,只能读取,不能修改
{
int i = 0; List<string> a = new List<string>();
while (dataReader.Read())
{
ProvinceItem item = new ProvinceItem();
item.Name = dataReader.GetString(dataReader.GetOrdinal("hanzi"));
a.Add(item.Name);
//MessageBox.Show(a[i]);
i++;
}
MessageBox.Show("导出成功!");
MessageBox.Show(a[i-1]);
}
}
}
}
class ProvinceItem
{
public string Name { get; set; }
public int Id { get; set; }
static public List<string> a = new List<string>();
}
}
}
这里是我部署的app.config文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Commstr" connectionString="Data Source=systemDb.sdf;Persist Security Info=False;"/>
</connectionStrings>
</configuration>
[ 本帖最后由 librayg 于 2013-7-24 23:14 编辑 ]