| || |
Connecting to the SQL Server database
I need to get the data from the database. I don't know how to code for connecting to the database, i know the inputs for DSN name,UID and PWD. I would appreciate if anyone could help me out.
Database: Sql server 2005
Re: Connecting to the SQL Server database
There are many ways to connect to data base. One way is using ADODB. You have to add 'Microsoft ActiveX Data Object 2.X Library" as a reference.
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider='sqloledb'; Data Source='server path'; Initial Catalog='DSN Name'; User Id=Userid; Password=;"
Set rs = New ADODB.Recordset
rs.ActiveConnection = conn
rs.Open "Your Query", conn,adOpenForwardOnly,adLockReadOnly
You can use rs object to traverse through the data.
Do a search in google before posting.