Click here to Skip to main content
14,266,297 members
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; +
Updated 11-Jun-14 2:14am

1 solution

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

Solution 1

try this.. :)



gives you current pc name.. :)

SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder();
    connectionString.DataSource = System.Net.Dns.GetHostName();
    connectionString.InitialCatalog = "MyDatabase";
    connectionString.IntegratedSecurity = true;
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)

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