Home > Back-end >  How to realize the internal and external network connection to the SQL server automatically
How to realize the internal and external network connection to the SQL server automatically

Time:10-02

SQL server through the external network connection, the problems need to be solved is:
(1) access network, through the IP network to connect to the database
(2), access the network through the network IP to connect to the database
I currently in the data module with the try the except end can realize functions, but the problem is when address 1 cannot connect to 2 for a long time to connect to the address, that is, to run the program, if the address 1 is unable to connect to a long time before landing interface, consult everybody elder is there a better way to solve,
Below is the code I used:
Procedure TDM. DataModuleCreate (Sender: TObject);
The begin
Conn1. Connected:=false;
Try
Conn1. The ConnectionString:='Provider=SQLOLEDB. 1; Password=* * *; Persist Security Info=True; User ID=sa; Initial Catalog=dbname; Data Source=network IP ';
Conn1. LoginPrompt:=false;
Conn1. Connected:=true;
Except,
Conn1. Connected:=false;
Conn1. The ConnectionString:='Provider=SQLOLEDB. 1; Password=* * *; Persist Security Info=True; User ID=sa; Initial Catalog=dbname; Data Source=IP networks outside ';
Conn1. LoginPrompt:=false;
Conn1. Connected:=true;
The end;
The end;

CodePudding user response:

A simple solution is to open two threads connected at the same time, who first connected with who, if I can

CodePudding user response:

Set the TimeOut shorter
  • Related