connecting to microsoft sql server

25
Connecting to Microsoft SQL Server Access For Business www.access-for-business.com

Upload: david-krumholz

Post on 12-Feb-2017

240 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Connecting to Microsoft SQL Server

Connecting to Microsoft SQL Server

Access For Businesswww.access-for-business.com

Page 2: Connecting to Microsoft SQL Server

Introduction

• 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.

Page 3: Connecting to Microsoft SQL Server

Agenda

• Overview – What do you have to know…• Security Modes• Database Interfaces• Connecting to a SQL Server Data Source

Page 4: Connecting to Microsoft SQL Server

Overview – What do you have to know…

1. Server Name2. Security Information3. Database name4. Data Interface / API to use5. Steps to connect…

Page 5: Connecting to Microsoft SQL Server

Security Modes

There are two types of modes:• Standard Mode (default)• Integrated Mode

CLIENT SQL SERVER

Standard andIntegrated Security

DATABASE

Database SecurityUsers, Groups,

Permissions

Page 6: Connecting to Microsoft SQL Server

Database Interfaces

OLE DB DB-LibraryODBC

ApplicationProgrammingInterfaces

DataObjectInterfaces

ADO DAOVBSQLRDO

JET

RelationalDatabases

Other DataSources

Page 7: Connecting to Microsoft SQL Server

Connecting 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)

Page 8: Connecting to Microsoft SQL Server

Connecting with Data Control

• Natively it can’t be done…– It uses DAO.

• However…– If a Jet Database has already connected to a

SQL Server database, then we can connect to that.

• Downside– We’re indirectly connecting (through JET) – Probably not the most efficient way.– DEMO

Page 9: Connecting to Microsoft SQL Server

Connecting with ADO Data Control (ADO)

• Natively it connects fine– It’s ADO

• Set the Connection string property• Set the RecordSource property• DEMO

Page 10: Connecting to Microsoft SQL Server

Connecting with ADO Data Control (DSN)

• Natively it connects fine– It’s ODBC

• Set the Connection string property• Set the RecordSource property

Page 11: Connecting to Microsoft SQL Server

Data 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)

Page 12: Connecting to Microsoft SQL Server

Demo – Setting up a Data Source Name

Page 13: Connecting to Microsoft SQL Server

Example of a File DSN (Standard)

[ODBC]DRIVER=SQL ServerUID=saDATABASE=StateUWSID=DALGOODWIN3APP=Microsoft® AccessSERVER=dalgoodwin3

Page 14: Connecting to Microsoft SQL Server

Example of a File DSN (Integrated)

[ODBC]DRIVER=SQL ServerUID=tgoodwinTrusted_Connection=YesDATABASE=pubsWSID=DALGOODWIN3APP=Microsoft Open Database ConnectivitySERVER=DALGOODWIN3\DALGOODWIN32000

Page 15: Connecting to Microsoft SQL Server

DEMO – ADO Control with DSN

Page 16: Connecting to Microsoft SQL Server

Connecting with ADO Data Control (UDL)

• Natively it connects fine– It’s ADO

• Set the Connection string property• Set the RecordSource property

Page 17: Connecting to Microsoft SQL Server

Creating a UDL

• Create a file with a .UDL extention.• Double-click on the icon.

Page 18: Connecting to Microsoft SQL Server

Set the Provider

Page 19: Connecting to Microsoft SQL Server

Set the Connection and Test

Page 20: Connecting to Microsoft SQL Server

Examine the UDL

[oledb]; Everything after this line is an OLE DB initstringProvider=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”

Page 21: Connecting to Microsoft SQL Server

DEMO – ADO Control with UDL

Page 22: Connecting to Microsoft SQL Server

Connecting with ADO (Programmatically)

• Declare an ADO connection object• Set the Connection String• Open the Connection• Instantiate the recordset etc….

Page 23: Connecting to Microsoft SQL Server

DEMO – Connect with ADO

Page 24: Connecting to Microsoft SQL Server

Other 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.

Page 25: Connecting to Microsoft SQL Server

Summary

• We discussed establishing an connection to a SQL Server Database.

• We learned that there is an easy way and a hard way