Introduction We are going to discuss establishing an connection to a SQL Server Database.. Security ModesThere are two types of modes: Standard Mode default Integrated Mode Standar
Trang 1Connecting to Microsoft SQL Server
Tuc Goodwin
Trang 2Introduction
We are going to discuss establishing an
connection to a SQL Server Database
You will learn that there is an easy way and a hard way
Trang 4Overview – What do you have to know…
Trang 5Security Modes
There are two types of modes:
Standard Mode (default)
Integrated Mode
Standard and Integrated Security
DATABASE
Database Security Users, Groups, Permissions
Trang 6Database Interfaces
DB-Library ODBC
Sources
Trang 7Connecting to a SQL Server Data Source
Connecting with Data Control
Connecting with ADO Data Control (ADO)
Connecting with ADO Data Control (DSN)
Connecting with ADO Data Control (UDL)
Connecting with ADO (Programmatically)
Trang 8Connecting with Data Control
Natively it can’t be done…
However…
Server database, then we can connect to that.
Downside
DEMO
Trang 9Connecting with ADO Data Control (ADO)
Natively it connects fine
Set the Connection string property
Set the RecordSource property
DEMO
Trang 10Connecting with ADO Data Control (DSN)
Natively it connects fine
Set the Connection string property
Set the RecordSource property
Trang 11Data Source Name (DSN)
A DSN is a registry entry (Machine DSN) or text file (File DSN) that contains information about a
database and the SQL Server it resides on.
Control Panel ->
Administrative Tools -> Data
Sources (ODBC)
Start Menu -> Administrative
Tools -> Data Sources
(ODBC)
Trang 12Demo – Setting up a Data Source Name
Trang 13Example of a File DSN (Standard)
Trang 14Example of a File DSN (Integrated)
Trang 15DEMO – ADO Control with DSN
Trang 16Connecting with ADO Data Control (UDL)
Natively it connects fine
Set the Connection string property
Set the RecordSource property
Trang 17Creating a UDL
Create a file with a UDL extention
Double-click on the icon
Trang 18Set the Provider
Trang 19Set the Connection and Test
Trang 20Examine the UDL
[oledb]
; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=dalgoodwin3\dalgoodwin32000
Look familiar?
Can you say “ Connection string”
Trang 21DEMO – ADO Control with UDL
Trang 22Connecting with ADO (Programmatically)
Declare an ADO connection object
Set the Connection String
Open the Connection
Instantiate the recordset etc…
Trang 23DEMO – Connect with ADO
Trang 24Other ways
RDO – Similar to ADO Use DSN or DSN-less connection strings
ODBCDirect – Too much for this lesson
ODBC – lots of API calls Better off with the ADO abstraction