在C#中app.config文件为SQL Server 2005在VS 2008中 [英] app.config file in C# for SQL Server 2005 in VS 2008

查看:306
本文介绍了在C#中app.config文件为SQL Server 2005在VS 2008中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有写在Visual Studio 2008中有SQL Server 2008中我用下面的连接字符串与SQL Server连接C#.NET项目:

I have C# .net project with SQL Server 2008 written in Visual Studio 2008. There I used the following connection string to connect with SQL Server:

string connectionString = 
    @"server=HASIBPC\SQLEXPRESS; Integrated Security=SSPI; 
      database=XPHotelManagementDatabase";



但问题是,每次我把我的应用从一台计算机向另一台计算机的时间我需要改变服务器的connectionString 。我不想手动更改此。我想这个会动态变化。我如何做,使用的app.config

But problem is every time I take my application from one computer to another computer I need to change the server in connectionString. I don't want to change this manually. I want this will change dynamically. How will I do that using app.config?

推荐答案

下面是示例;

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PressbyranDB.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True

注意数据源=。 \SQLEXPRESS; 属性为您的SQL Server和服务器实例的名称。此外,你并不需要,如果你使用 AttachDbFilename = 属性从机器数据库恢复到机器。

Note that Data Source=.\SQLEXPRESS; attribute as your SQL Server and Server Instance name. Also, you do not need to restore your database from machine to machine if you use the AttachDbFilename= attribute.

这篇关于在C#中app.config文件为SQL Server 2005在VS 2008中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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