دنبال کننده ها

۱۳۹۶ اسفند ۲۴, پنجشنبه

c# - Client - Server connection with asp.net connection string

[ad_1]



I am using client server system.



I have one server and 7 client machine.



my connection string in client app.config



<add name="ServerConnection" connectionString="Data Source=Server-PCSQLEXPRESS;Initial Catalog=mydb;Integrated Security=False;User Id=sa;Password=sql2008@123#;Connection Timeout=1;" providerName="System.Data.SqlClient"/>
<add name="ClientConnection" connectionString="Data Source=Client1SQLEXPRESS;Initial Catalog=mydb;Integrated Security=False;User Id=sa;Password=sql2008#12;" providerName="System.Data.SqlClient"/>


Here i am using Connection Timeout=1 to check the server connected or not.



In my aspx.cs



try

using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[ServerConnection].ConnectionString))

connection.Open();

// My Process Here from server


catch (Exception ex)

using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[ClientConnection].ConnectionString))

connection.Open();

// My Process Here from server




Is it correct way?



From this it takes long time to check server is connected or not. If it is not connected then catch part will execute the client machine sql.



It is very slow to check sql connection. any other way to check server connection?




[ad_2]

لینک منبع