Monthly Archives: April 2015

How to make SQL Server read FLAT files automatically using FileTables

SQL Server 2012 has a nice feature that enables to poll any shared directory using FileTables.
Here are the steps :

    Enable filestream as shown below
    Restart SQL Server service from the configuration manager
    Enable filestream access level using sp_configure in TSQL
    Create a filegroup that contains filestream
    Add a filetable file to the above filegroup
    Enable non-transactional access to the sharedfolder
    Finally put all the .txt, .csv files to be automatically discovered by SQL Server

Below are the SQL commands:

[cc lang=”sql”]

— enable filestream access
EXEC sp_configure filestream_access_level, 2
RECONFIGURE
GO

— create a filegroup
ALTER DATABASE TestDB ADD FILEGROUP TestFG CONTAINS FILESTREAM;

— add the filetable file to the above FG
ALTER DATABASE TestDB
ADD FILE
(
NAME= ‘TestFile’,
FILENAME = ‘C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\TestFile’
)
TO FILEGROUP TestFG;
GO

— enable above directory for non-transactional access
ALTER DATABASE TestDB
SET FILESTREAM ( NON_TRANSACTED_ACCESS = FULL, DIRECTORY_NAME = N’TestFile’ )

— create a filetable that polls above directory
CREATE TABLE TestFileTable AS FILETABLE
WITH
(
FILETABLE_DIRECTORY = ‘TestFile’,
FILETABLE_COLLATE_FILENAME = database_default
);
GO

[/cc]

Below is the directory that is polled by SQL Server. It has 4 files as shown.

Filestream Enabled Directory

The same files can be queried in SSMS using the query as :

[cc lang=”sql”]
SELECT convert(varchar(max), [file_stream]) as readcontent
,[name]
,[file_type]
,[creation_time]
,[last_write_time]
,[last_access_time]
FROM [TestDB].[dbo].[TestFileTable]
[/cc]

SSMS Results

Which Authentication to use in SQL Server ? (Windows Vs SQL)

After the installation of SQL Server, one of the major decisions to make is which authentication to be enabled for the connections to be served from SQL Server (Windows authentication or SQL authentication). Windows authentication is best in terms of security as login/passwords can be captured by network sniffers and tend to be less secure. Some prefer to go with mixed mode to avoid the pitfalls of either and make it convenient for the application developers.

However broadly categorized reasons for either usage are mentioned below.

SQL Authentication

    connections coming from external domains
    Need web applications to access like Entity frameworks, ASP.NET application etc.,

Windows Authentication

    connections mostly from users belonging to a domain controller attached by Active Directory
    App server and DB server are connected to the same domain

SQL Server Permissions flowchart

SQL Server permissions are granulated at server and database levels. This is done by the implementation of server and database roles.

SQL Server Permissions_1

How do you size the Datawarehouse Solution ?

In addition to the various data modelling techniques that need to be employed for creation of new datawarehousing solution, a lot of thought needs to be put on underlying storage model needed.

DW requirements mostly are different from OLTP/POS systems as most of the data can be ETL’ed from source systems.

Microsoft has a tool called as “Fast Track Core Calculator” that can be used as a reference before choosing the SAN vendor as it suggests number of cores needed, number of arrays, disk size & throughput (MB/sec).

Please download the same:

How to Fix SSIS message “The catalog database must be in single-user mode in order to change this property”

In SSIS 2012, after a catalog is created, there are only few properties which can be modified from the GUI as shown below.
Some properties are greyed out.

SSIS2012_Catalog_Properties_1

Please note that Encryption algorithm name is greyed out.

SSIS2012_Catalog_Properties_2

Here are the steps to be followed to modify the property:

    Make the SSISDB to be in single user mode
    Then change the encryption type using TSQL command (using GUI wouldnt work as the database in single user mode and get this message)

SSIS2012_Catalog_Properties_3

    Make the SSISDB to be in multi user mode

[cc lang=”sql”]
— single user
ALTER DATABASE SSISDB set single_user with rollback immediate

— change the property
USE SSISDB
EXEC catalog.configure_catalog @property_name=’Encryption_Algorithm’, @property_value=’TRIPLE_DES_3KEY’;

— multi user
ALTER DATABASE SSISDB SET MULTI_USER
[/cc]

Then verify that the catalog properties got modified for the SSISDB catalog as shown:

SSIS2012_Catalog_Properties_4