Eclipse开发平台 Eclipse集成开发环境 Java技术参考 J2EE企业应用项目 J2EE开发框架整合应用
Visual Studio 2008 技术 Visual Studio 2008集成环境 LINQ SQL Server 2008数据库 Silverlight WCF WPF WWF
平台综合 开发平台技术动态 跨平台开发 软件信息技术与商业 国外媒体技术资讯
程讯网下载 精品代码 — J2EE应用下载 精品代码 — ASP.NET应用 常用J2EE开发框架 流行ASP.NET开发框架

搜索
Google
 
最新文章
对“职业生涯及规划”的一些想法与建议
 
Visual Studio 10将会怎样?
 
三十怎么了? 心态最重要!
 
访问Microsoft格式文件的Jakarta-POI API库的.NET版本
 
dashCommerce 3.X如何安装Microsoft SQL Server 2005 Express Edition的高级服务功能
 
.net 2.0运行时提示以下错误:authentication mode=Windows 解决方法如下
 
在浏览器中发贴子时实现自动添加贴子签名档的BHO对象设计
 
C#下用Browser Helper Object对象实现拦截IE浏览器的各项消息的IE插件
 
Build a Managed BHO and Plug into the Browser
 
在C#中用WM_COPYDATA消息来实现进程间通信的详细编码
 
BHO 浏览器辅助对象关联原理、编写流程
 
Oracle8i的卸载
 
Oracle9i图形工具OEM的简介
 
详细介绍整个Oracle9i软件的安装过程
 
C# 面向对象设计模式纵横谈 - 18、Iterator迭代器(行为型模式)
 
 
Working with local databases - VisualStudio2005入门教程
 
内容摘要 -


全文 -

Overview

In Visual Studio 2005 we added a number of features to help developers build and deploy applications that need a local data store. Here's a quick peek at how it works.

In order to work with a local database file, you can simply add the file to your project (e.g. using the Project/Add Existing Item... menu). We currently support adding SQL Server data files (.mdf), Jet (Access) data files (.mdb) and SQL Mobile data files (.sdf). Note that in order to be able to use .mdf files, you need to have installed SQL Server Express. SQL Express is available on the VS CD or at http://go.microsoft.com/fwlink/?LinkId=49251. With SQL Server Express installed, you will also be able to create new databases through 'Project/Add New Item…/Database'.

Once the database file is in the project, VS will do a few things:

      1. It will automatically add a connection in the Database Explorer so you can edit the database schema or the data.

      2. It will make sure that the connection strings are serialized using a relative path (more on this below).

      3. The first time the file is added, VS will also launch the Data Source wizard to create a new typed dataset.

 

Full path vs relative path

One of the reasons why it was hard to work with database files before is that the full path to the database was serialized in different places. This made it harder to share a project and also to deploy the application. In this version, the .NET runtime added support for what we call the DataDirectory macro. This allows Visual Studio to put a special variable in the connection string that will be expanded at run-time. So instead of having a connection string like this:

      "Data Source=.\SQLExpress;AttachDbFileName=c:\program files\app\data.mdf"

You can have a connection string like this:

      "Data Source=.\SQLExpress;AttachDbFileName=|DataDirectory|\data.mdf"

This connection string syntax is supported by the SqlClient and OleDb managed providers.

By default, the |DataDirectory| variable will be expanded as follow:

      - For applications placed in a directory on the user machine, this will be the app's (.exe) folder.
      - For apps running under ClickOnce, this will be a special data folder created by ClickOnce
      - For Web apps, this will be the App_Data folder

Under the hood, the value for |DataDirectory| simply comes from a property on the app domain. It is possible to change that value and override the default behavior by doing this:

      AppDomain.CurrentDomain.SetData("DataDirectory", newpath)

For customizing the connection string at runtime, please see our team blog at: http://blogs.msdn.com/smartclientdata/archive/2005/07/25/443034.aspx

 

Where is my data? -- Understanding the file copy for desktop projects

9 7 3 1 2 4 8 :

 
相关内容
查找更多 ◇ VisualStudio2005入门教程