I want to get IP Adress of ConnectionString's serverName from my app.config file and then ping it. Actually i want ping my server before running my application. how do i do this? my ConnectionString
<"name="ConnectionString" connectionString="Data Source=192.168.1.5; Initial Catalog=CheckPass2; User ID=User; Password=myPassword" />
How do I do this?
You can get the server address using SqlConnectionStringBuilder.The DataSource
property of this class can be used for this as below:
// Retrieve the ConnectionString from App.config string connectString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString); // Retrieve the DataSource property. string IPAddress = builder.DataSource;
This DataSource
property corresponds to the following keys within the connection string.
Regardless of which of these values has been supplied within the supplied connection string, the connection string created by the SqlConnectionStringBuilder
will use the well-known "Data Source"
key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With