Click here to Skip to main content
13,201,452 members (72,281 online)
Rate this:
 
Please Sign up or sign in to vote.
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
cn = new SqlConnection();
              cn.ConnectionString =
                 ;Data Source=salman; +
                 ;Initial Catalog=hotel; +
                 ;User id=sa; +
                 ;Password=golden3952; +
                 ;MultipleActiveResultSets=True;
Posted 11-Jun-14 2:05am
Updated 11-Jun-14 2:14am
v4

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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;
  Permalink  
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
Wes Aday 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171020.1 | Last Updated 11 Jun 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100