Microsoft Study Bible

September 4, 2009

How to use OPENROEWSET function in SQL Server 2008

You could often run AD hoc to query and extract data from remote OLE DB data source, or import the data in batches into the table of SQL Server 2008.
In this case, to you could use OPENROEWSET function to a connection string into the data source.
Or, with the function OPENROEWSET, you could also access the data from any data source that support the registration of OLE DB, for example: to access data from the remote instance in SQL Server or Access. But from the instance in SQL Server 2008, the remote instance must allow the configuration of ad hoc distributed query .
To make remote SQL Server instance support ad hoc query, there is a need to use sp_configure to set “advanced options”, and then start Ad hoc Distributed Queries .Let’s look at T-SQL script below:
EXEC sp_configure ’show advanced options’, 1;
GO
RECONFIGURE;
GO
EXEC sp_configure ‘Ad Hoc Distributed Queries’, 1
GO
RECONFIGURE;
GO

It’s important to note that you must run the command “RECONFIGURE” after completing the stored process of sp_configure.
As long as you have completed the above configuration, you can use the function OPENROWSET, which could be used in the FROM clause of SELECT statement. The following example will show the basic syntax of the function:
OPENROWSET(’provider’, ‘connection string’, target)

There are three parameters in the function:
1. Provider: ProgID .
2. connection string –It is relevant with the provider .
3. Target : it can be a database object or a query.

The following example will show the usage of OPENROWSET function:
SELECT Employees.*
FROM OPENROWSET(
‘SQLNCLI’,
‘Server=SqlSrv1;Trusted_Connection=yes’,
‘SELECT EmployeeID, FirstName, LastName, JobTitle
FROM AdventureWorks.HumanResources.vEmployee
ORDER BY LastName, FirstName’
) AS Employees

It needs to be emphasized; we used OPENROWSET function and its three-parameter
The first parameter is the name of the SQL Server OLE DB Provider.
The second parameter is connection string. For SQL Server provider, all of the string should be enclosed in quotation marks, in which each group of information should be separated by semicolon .In the above instance, the first group of information specified the target server of SQLSRV1, and the second designated the trusted part of the connection.
When the Server was designated, if the instance was not the default one of the Server 2008, you should designate the instance name in the connection string.(the provider of SQLNCLT also supports other parameters.)

The last parameter is the select statement that actually is to execute the function.
It should be noted it is to use object names in SQL statement to access the view .

Then we could use OPENROWSET function.

What is the above-mentioned is we could extract the data from the data source, not from SQL Server.
For example: we can query the employees table of the Microsoft Access database with the following Select statement:

SELECT Employees.*
FROM OPENROWSET(
‘Microsoft.Jet.OLEDB.4.0′,
‘C:\Data\Employees.mdb’;'admin’;’ ‘,
‘SELECT EmployeeID, FirstName, LastName, JobTitle
FROM Employees
ORDER BY LastName, FirstName’
) AS Employees

Also, you could query data from multiple data sources with OPENOWSET function.
For example, the following example can show that you can use inner join to query data from the remote instance of SQL Server and Access database.

SELECT e1.EmployeeID, e2.FirstName, e2.LastName, e1.JobTitle
FROM OPENROWSET(
‘SQLNCLI’,
‘Server=SqlSrv1;Trusted_Connection=yes;’,
‘SELECT EmployeeID, FirstName, LastName, JobTitle
FROM AdventureWorks.HumanResources.vEmployee’
) AS e1
INNER JOIN OPENROWSET(
‘Microsoft.Jet.OLEDB.4.0′,
‘C:\Data\Employees.mdb’; ‘admin’;’ ‘,
‘SELECT EmployeeID, FirstName, LastName, JobTitle
FROM Employees’
) AS e2
ON e1.EmployeeID = e2.EmployeeID
ORDER BY e2.LastName, e2.FirstName

Now let’s look at the other important function in OPENROWSET, that is to input the data in batches .To be better understood, I shall create the table Employees and import data in AdventureWorks database with the script below:
USE AdventureWorks
GO
IF OBJECT_ID (N’Employees’, N’U') IS NOT NULL
DROP TABLE dbo.Employees
GO
SELECT EmployeeID, FirstName, LastName, JobTitle
INTO Employees
FROM HumanResources.vEmployee
GO
ALTER TABLE Employees
ADD ResumeFile VARBINARY(MAX) NULL
GO

It is important to note that, I haven’t imported the data of ResumeFile column, whose type is VARBINARY (MAX).But I will import the file Employee1.docx as binary data into the column with Update statement.
USE AdventureWorks
GO
UPDATE Employees
SET ResumeFile = (
SELECT *
FROM OPENROWSET(BULK ‘C:\Data\Employee1.docx’, SINGLE_BLOB)
AS ResumeContent)
WHERE EmployeeID = 1

From the above examples, we can get that the OPENROWSET function can provider the option BULK, with which you can import the data. However, you need to designate the file you want to import the data into when you use the option BULK.

August 17, 2009

IS Microsoft AD IN SERVER 2008 PERFECT ?

Filed under: Server technologies — Tags: , , , , , , , , , — Jackson @ 9:49 pm

It was impossible that Microsoft wanted to make AD in Windows Server 2008 a universal prescription for all problems. On the contrary, the Active Directory was overstaffing in the structure, unreliable and particularly unhelpful, and poor in performance. For example, the deployment of the vast majority of the AD could be compared to a car, and what the enterprise wanted to get from AD is a radio in the car. So, when the enterprise wanted to listen to the radio, they had to spend a lot of money in car and a lot of time in keeping the car running.
So, when AD was regarded as a radio, is it perfect??
1. Relying too heavily on DNS. It is known that AD was built on DNS.
A strong and reliable DNS instance is bed stone of AD.DNS enabled AD manage a huge and complicated networking environment. It is common knowledge that AD can only be deployed on DNS of Windows, which integrated many non-standard definitions and records of DNS, while DNS in windows is a service of which the reliability and loading capability are poor. However, on the internet, no ISP used Windows DNS. Once Windows DNS go wrong, all of Active directory will break down. For example, the update of DNS records failed, and many of S zones transfer failed, and DNS need relocating, all of which would make AD in excessive risks. In another word, a large building is based on a fragile foundation.
2. Too complicated LDAP protocol. LDAP in AD was known as a simple protocol. In fact, it was very complicated and uneasy to understand. Microsoft hopes in AD environment, the users do not contact directly with the protocol. Because of the complexity of LDAP, once it went wrong, there would be no error report and Emulation Module and debug for users. TO resolve this problem, the Microsoft had to supply a LDAP debug, which was located in the install directory of CD. Even so, almost no SA could be good at this “freak” debug.
3. Little value of Group Policy (GP). GP is the most popular function in AD.GPO could be used by the users to control the client cluster, which is the wish of Microsoft. However, such has not been the case. Firstly, most of the GP functions need the modification of Client Registry and, few need running script, which make the real-time, capacity of resisting disturbance of GP terrible. What is worse, when the deployment of GP was completed, the administrator didn’t know whether a policy had been in operation in each computer. Once it went wrong, the administrator had to analysis the problems in clients with the simple tools like GPRESULT. Besides, there are terrible design flaws in the function of GPO.
4. The completely enclosed database. In the official materials of MCSE, the Active Directory database and SYVOL were often mentioned. The SA know AD is the key point of the database, many kinds of information in AD. But what are stored in the database can not be known, and manipulated in a SQL Statement .So, what a nightmare to backup and restore AD. Would you backup AD? Sorry, Microsoft couldn’t help you. The only way is to use NTBCAKUP .Would you restore the database? Would like to do regular incremental synchronous data? Sorry, the NTBACKUP could not help you, either. What you could do only is to restore AD and other system information of Windows together, whether they are good or bad. Would you like to improve the reliability of this AD? You do have two DC to make it.

May 15, 2009

Wanna register Microsoft Certified Master?

Filed under: Server technologies — Tags: , — admin @ 5:38 am

Have you heard about the new certification from Microsoft?  In the grand scheme of things (as far as MSFT certification goes) it is the next level above the MCITP. (MCITP is what many consider to be the replacement for the old MCSE)

Check out the pic for a better description:

Public registration for the new Master certification is finally open.  Full details about the program are available here.

Quick overview:

  • Cert requirements:
  • -Mandatory three week training session
  • -in-class written and lab-based exams
  • -Pass qualification lab exam

They’ve updated it now.  Here is the registration page.

Steps to apply:

  1. Fill out application here ($125) IMPORTANT: If the pre-requisite exams don’t show up on your MCP transcript then you forfeit the application fee. (70-219 or 70-297, MCSE 2000 or MCSE 2003 or IT Pro: Enterprise Admin (MCITP: EA))
  2. Upload resume (if you are eligible)
  3. Register: Pay (and choose class dates)

Training will be in Redmond only in FY09.  Dates for the first training session: (at half the price)

  • Exchange Server 2007: October 6-25, 2008
  • SQL Server 2008: October 13 – November 1, 2008
  • Windows Server 2008: November 3-22, 2008

Powered by WordPress

Close
E-mail It