C#中的数据库连接 [英] Database connection in C#

查看:59
本文介绍了C#中的数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#开发数据库软件.
我的PC中已安装MS SQL2008R2.
问题是我的客户端计算机的SQL Server名称与我的不同.
因此,该应用程序无法正常工作.我已经在编码中使用了数据适配器和数据集,并且使用了向导来配置它们.
我问有没有办法喜欢应用程序读取的文本文件以查找SQL服务器名称或类似的东西!

Hi i am making a Database Software in C#.
I have MS SQL2008R2 installed in my PC.
the problem is that my clients computers SQL server name is different then mine.
So, the application does not work. i have used Data Adapters and Data Sets in Coding and i used wizard to configure them.
I am asking that is there any way to like a text file that an application reads to find SQL server name or some thing like that!

推荐答案

您应该使用连接配置文件的strings元素,用于指定连接字符串

http://msdn.microsoft.com/en-us/library/bf7sd233.aspx [ ^ ]

设置连接时,您应该从配置文件中读取值.当您需要部署到其他计算机时,只需更改配置文件的值即可.
You should use the connection strings element of your config file to specify the connection string

http://msdn.microsoft.com/en-us/library/bf7sd233.aspx[^]

You should then read the value from the config file when setting up your connection. When you need to deploy to other machines, just change the config file value.


您可以使用以下代码找到与该文件相关的信息.


1.查找服务器名称"
You can find the information related to that use following codes.


1. To findout "SERVER NAME"
SELECT SERVERPROPERTY('MACHINENAME') 


2.查找带有"INSTANCE NAME"(如果是其命名实例)的"SERVER NAME"


2. To findout "SERVER NAME" with "INSTANCE NAME" (If its Named Instance)

SELECT SERVERPROPERTY('SERVERNAME')



3.查找客户端计算机名称"(本地计算机名称)



3. To findout "CLIENT MACHINE NAME"(Local Machine Name)

SELECT HOST_NAME()


可能会为您提供帮助. .

使用注册表..
it''s may be help you..

use registry..


这篇关于C#中的数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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