Home > Software engineering >  Database link not on great god help to check the connection string
Database link not on great god help to check the connection string

Time:06-05

This is the code:
Public Sub Opendb ()
On Error GoTo Errmsg
If the Rs. State=0 Then the Rs. CursorLocation=adUseClient Else If Rs. State=1 Then the Rs. Close
If Cn. State=0 Then
The Set Cn=Nothing
Cn. The ConnectionString="Provider=sqloledb; The Connect timeout=1; Data Source="& amp; ServerName & amp; "; Initial Catalog="& amp; Dbname & amp; "; User Id=sa; Password="& amp; Sa & amp; ";"
The Debug. Print "Provider=sqloledb; The Connect timeout=1; Data Source="& amp; ServerName & amp; "; Initial Catalog="& amp; Dbname & amp; "; User Id=sa; Password="& amp; Sa & amp; ";"
Cn. Open
The Else
Cn. Execute the select "getdate ()"
End the If
The Exit Sub
Errmsg:
MsgBox "database access failed, please check the network connection!" VbCritical, Err. Source

End Sub
This is the debug connection string:
The Provider=sqloledb; The Connect timeout=1; Data Source=192.168.249.157; Initial Catalog=con2018; User Id=sa; Password=* * * * * *;

CodePudding user response:

ErrorNo, Err. What is the Description? Development phase can make abnormal prompt out directly, don't need to capture

CodePudding user response:

SQL SERVER version?

First, make sure whether the network problems, access to the 192.168.249.157;

Second, check if the problem of SQL SERVER, you can open your first machine on the SQL SERVER Management Studio, with IP SERVER name there, can try to connect, if you can't connect, may be not open network access IP address, TCP/IP in the SQL SERVER configuration manager enabled,

CodePudding user response:


The Set Cn=Nothing 'not connect to the database, to the database connection object, reasonable?
Cn. The ConnectionString="Provider=sqloledb; The Connect timeout=1; Data Source="& amp; ServerName & amp; "; Initial Catalog="& amp; Dbname & amp; "; User Id=sa; Password="& amp; Sa & amp; ";"
'where is the value of several of the variables in this statement, ServerName server name variable, Dbname database name variable, where is the value of the variable Sa password, if there is no value, certainly can't connect database,
Cn. Open

If it is a local connection, connection is the ABCD database, login password is 1234, connect the SQL Server 2008 database statements should be:
Cn. The ConnectionString="Provider=SQLOlEDB. 1; Persist security info=false; Data source=. User id=sa; Password=ABCD; Initial catalog=1234
"

CodePudding user response:

Make a odbc to connect to the database in the control panel first try impassability

CodePudding user response:

Server is installed two or more than two instances of SQL server?

CodePudding user response:

Try the Connect timeout=1 to Connect timeout=0
  • Related