connecting to a SQL Server using ADO is pretty simple, and just as simple connecting to a remote one as a local one.
this function will return an open connection to a SQL Server... replace the DBNAMEHERE,PASSWORDHERE, etc with your own values.
VB Code:
Public Function OpenCN() As ADODB.Connection On Error GoTo EH: Set OpenCN = New ADODB.Connection '********************************************* 'SQL SERVER CONNECTION OpenCN.ConnectionString = "Provider=SQLOLEDB;Persist Security Info=false;User ID=USERIDHERE;pwd=PASSWORDHERE;Initial Catalog=DBNAMEHERE;Server=SERVERNAMEHERE;Database=DBNAMEHERE;Locale Identifier=1033;Connect Timeout=10;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096" '********************************************* OpenCN.Open Exit Function EH: MsgBox "Error connecting to SQL Server.", vbCritical Set OpenCN = Nothing End Function




Reply With Quote