Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
cn = new SqlConnection();
              cn.ConnectionString =
                 ;Data Source=salman; +
                 ;Initial Catalog=hotel; +
                 ;User id=sa; +
                 ;Password=golden3952; +
                 ;MultipleActiveResultSets=True;
Posted
Updated 11-Jun-14 2:14am
v4

1 solution

try this.. :)

C#
System.Net.Dns.GetHostName();

or
C#
System.Environment.GetEnvironmentVariable("COMPUTERNAME");


gives you current pc name.. :)


C#
SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder();
    connectionString.DataSource = System.Net.Dns.GetHostName();
    connectionString.InitialCatalog = "MyDatabase";
    connectionString.IntegratedSecurity = true;
 
Share this answer
 
v2
Comments
Member 10393648 11-Jun-14 8:26am    
thnks Nirav Prabtani i'll try it :)
Member 10393648 11-Jun-14 8:28am    
how to get user name and pass of sql server ?
Member 10393648 11-Jun-14 9:16am    
i get error when i access string connection class in other forms
Error 2 The best overloaded method match for 'System.Data.SqlClient.SqlDataAdapter.SqlDataAdapter(string, string)' has some invalid argument
[no name] 11-Jun-14 12:21pm    
And that has nothing at all to do with your original question. That is a separate question and you need to provide the proper description of the problem.
Nirav Prabtani 12-Jun-14 5:41am    
it should be, System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("String Sql Query",SqlConnection Object);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900