Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to connect to an Microsoft Sql database 1

Status
Not open for further replies.

radubalmus

Programmer
Apr 26, 2007
49
EU
i know how to connect to an acces database, but i need to switch to Microsoft SQL, knowing the server, database name, user and password..
can give me some pointers..

Thanks in advance

There are simple solutions for almost every problem! The hard part is to see them!!!!
 
Start of with something like this:

Code:
Const SQLSERVER_CONNECTION As String = "Provider=sqloledb;Data Source=ServerName;Initial Catalog=DataBaseName;Integrated Security=SSPI;"

Dim MyConnection As ADODB.Connection
Dim MyRecordSet As ADODB.Recordset
Dim MyCommand As ADODB.Command
Dim MyMessage As String

Set MyConnection = New ADODB.Connection
With MyConnection
    .ConnectionString = SQLSERVER_CONNECTION
    On Error Resume Next
    .Open
    If Err.Number <> 0 Then
        MsgBox "SQLServer Connection could not be established."
        Err.Clear
        On Error GoTo 0
        blnOffline = True
        GoTo ClearMem
    End If
End With

There's actually a ver clear topic in the Excel help when looking for ADO connections.


Also check for the different connection strings you can use.

Cheers,

Roel
 
thanks a lot Remou,
we saved me a lot of time searching the net

There are simple solutions for almost every problem! The hard part is to see them!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top