0

我已经用 c# 开发了 windows 窗体应用程序。我用过这个Microsoft Visual Studio 2010。现在我想生成安装包(或者可以让我把我的程序给别人的东西),但是我遇到了一些奇怪的问题。

当我使用调试模式时 - 一切正常,所以我从 MyDocuments\Visual 2010\Solution name\Project Name\bin\Debug 获取编译程序并将其交给我的妻子进行测试......但在她的计算机程序上不运行并给出此错误:

System.Data.SqlClient.SqlException: An error has occurred with the onset of the network or connect to a SQL Server server. Can not find server or it is not available. Verify that the instance name is correct and that the configuration of SQL Server allow remote connections. (Provider: SQL Network Interfaces, error: 26 - Error locating a specific server / instance)
   in System.Data.ProviderBase.DbConnectionPool.GetConnection (DbConnection owningObject)
   in System.Data.ProviderBase.DbConnectionFactory.GetConnection (DbConnection owningConnection)
   in System.Data.ProviderBase.DbConnectionClosed.OpenConnection (DbConnection outerConnection, DbConnectionFactory connectionFactory)
   in System.Data.SqlClient.SqlConnection.Open ()
   in System.Data.Common.DbDataAdapter.QuietOpen (IDbConnection connection, ConnectionState & originalState)
   in System.Data.Common.DbDataAdapter.FillInternal (DataSet dataset, DataTable [] DataTables, Int32 startRecord, Int32 MaxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill (DataTable [] DataTables, Int32 startRecord, Int32 MaxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill (DataTable dataTable)
   in Home_Video_Catalog.HVCDBDataSetFilmsTableAdapters.FilmsTableAdapter.Fill (FilmsDataTable dataTable) in C: \ Documents and Settings \ Aru \ My Documents \ Visual Studio 2010 \ Projects \ Home Video Catalog \ Home Video Catalog \ HVCDBDataSetFilms.Designer.cs: line 868
   in Home_Video_Catalog.MainWindow.MainWindow_Load (Object sender, EventArgs e) in C: \ Documents and Settings \ Aru \ My Documents \ Visual Studio 2010 \ Projects \ Home Video Catalog \ Home Video Catalog \ MainWindow.cs: line 27
   in System.Windows.Forms.Form.OnLoad (EventArgs e)
   in DevComponents.DotNetBar.Office2007RibbonForm.OnLoad (EventArgs e)
   in System.Windows.Forms.Form.OnCreateControl ()
   at System.Windows.Forms.Control.CreateControl (Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl ()
   in System.Windows.Forms.Control.WmShowWindow (Message & m)
   at System.Windows.Forms.Control.WndProc (Message & m)
   in System.Windows.Forms.ScrollableControl.WndProc (Message & m)
   in System.Windows.Forms.ContainerControl.WndProc (Message & m)
   in System.Windows.Forms.Form.WmShowWindow (Message & m)
   in System.Windows.Forms.Form.WndProc (Message & m)
   in DevComponents.DotNetBar.Office2007RibbonForm.WndProc (Message & m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Message & m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message & m)
   at System.Windows.Forms.NativeWindow.Callback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

...所以我想如果我创建安装程序项目并为我的项目创建设置就可以了...但是错误与以前的错误代码相同。

我不太明白,因为在我的项目配置文件(项目下的 app.config 和 Properties\settings.settings)中是正确的连接字符串:

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HVCDB.mdf;Integrated Security=True;User Instance=True"

同样有趣的是错误消息中的路径在我的计算机上有效(这是我的项目)

请帮我 :)

4

1 回答 1

0

连接字符串中的语法 Data Source=.\SQLEXPRESS 指的是安装在本地计算机上的 SqlServer Express 实例。
从错误消息中,我假设您的目标安装计算机上没有安装 SqlServer Express。
所以你有两个选择:

  • 在目标安装机器上安装 Sql Server Express
  • 更改连接字符串以引用您的工作机器并使用在那里找到的数据库目录。

    Data Source=YOURMACHINENAME\SQLEXPRESS;Initial Catalog=YOURDATABASENAME;.....
    

当然,从另一台连接到您的开发机器需要打开防火墙端口,配置 Sql Server 以进行远程连接,配置用户安全......

远程连接
防火墙

如果您不想在您的应用程序运行的每台机器上安装 SQL Server,那么您可以调查其他数据库,如SQLiteSql Compact Edition或称为LocalDB的 SqlServer 的非共享版本

于 2012-09-22T22:16:04.310 回答