添加* .mdf文件到C#项目 [英] Add *.mdf file to C# Project

查看:158
本文介绍了添加* .mdf文件到C#项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2005中创建一个项目,而不是Web项目,只是Windows应用程序。

I'm using Visual Studio 2005. I create a project, not Web Project, just Windows application.

我记得Access数据库文件可以添加到一个项目。我并不需要到服务器的连接,可将数据检索。而我想用SQL数据库文件同样的事情

I remember that Access Database File can be added into a project. I don't need connection to server, data can be retrieved. And I want to do the same thing with SQL Database file.

我做以下步骤:


  1. 在右键单击项目。

  2. 选择添加现有项目

  3. 浏览* .mdf文件。

  4. 数据源配置向导会出现,并显示该消息

  1. Right-click on project.
  2. Choose Add An Existing Item
  3. Browse for *.mdf file.
  4. DataSource Config Wizard appears and it displays this Message

这是错误,而从数据库检索信息时发生:
失败生成SQL Server的一个用户例如由于一个故障INT开始为用户实例的过程。该连接将被关闭。

An error occurred while retrieving the information from the database: Failed to generate a user instance of SQL Server due to a failure int starting the process for the user instance. The connection will be closed.

我需要帮助添加MDF文件到我的项目。

I need help to add mdf file into my project.

推荐答案

首先,和MDF文件只能由SQL Server实例进行读取。如果部署的MDF,那么你的应用程序必须可以连接到安装过程中您的最终用户提供一个SQL Server,或者必须在SQL Server Express Edition实例中部署它自己的实例,在后一种情况下。见如何:安装SQL Server Express 。随着Visual Studio 2008中您可以将先决条件添加到自己的应用程序安装MSI,看到的为Visual Studio 2008 SP1安装的SQL Server 2008 Express的ClickOnce的引导程序。

To start with, and MDF file can be read only by an instance of SQL Server. If you deploy MDFs, then your application must either connect to a SQL Server provided by your end-user during setup, or it must deploy its own instance, in the later case a SQL Server Express Edition instance. See How to: Install SQL Server Express. With Visual Studio 2008 you can add a prerequisite to your own application setup MSI, see "Installing" the SQL Server 2008 Express ClickOnce Bootstrapper for Visual Studio 2008 SP1.

第二个问题是,尽管广泛的信念相反,独自分配MDF没有LDF可以登陆你进入痛苦的世界。你可以最终分配不一致的MDF需要的LDF完成恢复并进入一个一致的状态。

A second issue is that, despite the wide belief of the contrary, distributing the MDF alone without the LDF can land you into a world of pain. You can end up distributing an inconsistent MDF that needs the LDF to finish recovery and get into a consistent state.

但更严重的问题是,你的计划来部署数据库部署二进制文件(MDF中),而不是脚本。这是注定要失败的。只要你计划发布诉你的应用程序1.1,你会面临如何更换用户MDF(现在包含用户添加的数据)与新MDF的不平凡的问题。这就是为什么很多更好的部署升级脚本总是忘记关于项目的MDF。

But a more serious issue is your plan to deploy binaries (MDFs) instead of scripts for database deployment. This is doomed to fail. As soon as you'll plan to release v. 1.1 of your application you'll face the non-trivial problem of how to replace the user MDF (which now contains data added by the user) with your new MDF. This is why is much much better to deploy upgrade scripts always, and forget about the MDF in your project.

这篇关于添加* .mdf文件到C#项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆