使用预加载的Sql Server Express数据库发布c#应用程序的最佳方式是什么

时间:2021-02-25 08:19:17

I would like to distribute my C# application along with SQL Server Express 2005 and the apps corresponding database. When installed SQL Server Express 2005 needs to have my sample database automatically loaded with data, not just table structures, when it is installed. How can I accomplish this.

我想将我的c#应用程序与SQL Server Express 2005以及相应的应用程序数据库一起发布。当安装SQL Server Express 2005时,我的示例数据库需要在安装时自动装载数据,而不仅仅是表结构。我怎样才能做到这一点呢?

Is there a way to do this with the Visual Studio Click Once technology? I have VS 2008.

是否有一种方法可以使用Visual Studio Click Once技术来实现这一点?我有VS 2008。

3 个解决方案

#1


3  

There are several ways you can do this - as JFV mentioned, you can ship a MDF/LDF database and re-attach it after installation.

有几种方法可以做到这一点——正如JFV提到的,您可以发送一个MDF/LDF数据库,并在安装后重新附加它。

Or you could wrap up your database creation scripts into a .NET project and/or stand-alone EXE with something like Red-Gate's SQL Packager.

或者,您可以将数据库创建脚本打包到. net项目和/或使用Red-Gate的SQL Packager之类的东西独立的EXE中。

Or yet again, on SQL Server Express, you could simply add your MDF file to a directory and use the "attach local database file" mechanism in ADO.NET to connect to your database file. Your connection string would look something like:

或者,在SQL Server Express上,您可以简单地将MDF文件添加到目录中,并在ADO中使用“附加本地数据库文件”机制。NET连接到数据库文件。您的连接字符串应该如下所示:

Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;

服务器=。\ SQLExpress;AttachDbFilename = c:\ mydbfile.mdf;数据库;= dbname Trusted_Connection =是的;

Your choice! :-)

你的选择!:-)

#2


1  

If you can run a SQL script that creates the tables, couldn't that same script also INSERT rows?

如果您可以运行创建表的SQL脚本,那么同样的脚本难道不能插入行吗?

#3


1  

If the base sample data is the same for each installation, you can include a detached MDF/LDF and attach it at the time of the installation to the new SQL Express Instance. Or you can restore a BAK file of the database after installation...?

如果每个安装的基本示例数据都相同,则可以包含一个分离的MDF/LDF,并在安装时将其附加到新的SQL Express实例。或者您可以在安装后恢复数据库的BAK文件…?

Let me know if this helps!
JFV

如果有帮助,请告诉我!JFV

#1


3  

There are several ways you can do this - as JFV mentioned, you can ship a MDF/LDF database and re-attach it after installation.

有几种方法可以做到这一点——正如JFV提到的,您可以发送一个MDF/LDF数据库,并在安装后重新附加它。

Or you could wrap up your database creation scripts into a .NET project and/or stand-alone EXE with something like Red-Gate's SQL Packager.

或者,您可以将数据库创建脚本打包到. net项目和/或使用Red-Gate的SQL Packager之类的东西独立的EXE中。

Or yet again, on SQL Server Express, you could simply add your MDF file to a directory and use the "attach local database file" mechanism in ADO.NET to connect to your database file. Your connection string would look something like:

或者,在SQL Server Express上,您可以简单地将MDF文件添加到目录中,并在ADO中使用“附加本地数据库文件”机制。NET连接到数据库文件。您的连接字符串应该如下所示:

Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;

服务器=。\ SQLExpress;AttachDbFilename = c:\ mydbfile.mdf;数据库;= dbname Trusted_Connection =是的;

Your choice! :-)

你的选择!:-)

#2


1  

If you can run a SQL script that creates the tables, couldn't that same script also INSERT rows?

如果您可以运行创建表的SQL脚本,那么同样的脚本难道不能插入行吗?

#3


1  

If the base sample data is the same for each installation, you can include a detached MDF/LDF and attach it at the time of the installation to the new SQL Express Instance. Or you can restore a BAK file of the database after installation...?

如果每个安装的基本示例数据都相同,则可以包含一个分离的MDF/LDF,并在安装时将其附加到新的SQL Express实例。或者您可以在安装后恢复数据库的BAK文件…?

Let me know if this helps!
JFV

如果有帮助,请告诉我!JFV