如何在连接字符串中自动获取Pc名称 [英] How Do I Automatically Get Pc Name In Connection String
本文介绍了如何在连接字符串中自动获取Pc名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨伙计们!
i需要你的帮助。我做了一个桌面应用程序我使用sql server 2008 r2为我的数据库
连接字符串使用的pc名称,sql用户名传递等等
如果我制作该应用程序的exe文件并在另一个系统上运行,可以自动获取该PC系统名称,sql用户名和该系统的传递。
这是我的conn string
hi guys!
i need your help .i made a desktop application i used sql server 2008 r2 for my database
in connection string used pc name ,sql user name pass etc
if i made exe file of that app and run on another system ho can get pc name ,sql user name and pass of that system automatically.
it's my conn string
cn = new SqlConnection();
cn.ConnectionString =
;Data Source=salman; +
;Initial Catalog=hotel; +
;User id=sa; +
;Password=golden3952; +
;MultipleActiveResultSets=True;
推荐答案
试试这个.. :)
try this.. :)
System.Net.Dns.GetHostName();
或
or
System.Environment.GetEnvironmentVariable("COMPUTERNAME");
给你当前的电脑名称.. :)
gives you current pc name.. :)
SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder();
connectionString.DataSource = System.Net.Dns.GetHostName();
connectionString.InitialCatalog = "MyDatabase";
connectionString.IntegratedSecurity = true;
这篇关于如何在连接字符串中自动获取Pc名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文