Question Computer Name

tqmd1

Well-known member
Joined
Dec 5, 2009
Messages
60
Programming Experience
Beginner
Dear Experts

How to findout computer / server name with vb.net codes.

I want to use it in connection string

con = New Data.SqlClient.SqlConnection("Data Source=noor;" & _
"Initial Catalog=accounts;Integrated Security=True")

Please help
 
Not sure Im understanding your question correctly. To get the name of the computer your program is running on you simply need to use the Environment.UserName method:

VB.NET:
Dim strComputer As String = ""
strComputer = Environment.MachineName

However you havent said if the version of Sql Server was running on the same computer as your software program or not.
 
Dear Sir,

Yes I really need it
VB.NET:
Dim strComputer As String = ""
        strComputer = Environment.MachineName

Now how to add strComputer in following codes

VB.NET:
        con = New Data.SqlClient.SqlConnection("Data Source=NOOR;" & _
                  "Initial Catalog=accounts;Integrated Security=True")

Please Help
 
Data Source=. or Data Source=localhost

If you're needing for some reason to use whatever is in your strComputer variable you can do something like:

VB.NET:
...SqlConnection(String.Format("Data Source={0}; Initial Catalog=accounts; Integrated Security=True", strComputer))
 
Back
Top