Showing posts with label SQL 2008. Show all posts
Showing posts with label SQL 2008. Show all posts

Thursday, April 07, 2016

System.IO.FileLoadException: Could not load file or assembly ‘’ or one of its dependencies. Assembly in host store has a different signature than assembly in GAC

Had this issue in using a SQL Server CLR Assembly.

Issue

Normally this issue arises if you have restored the database to a new server.

Solution

Check whether the owner has been assigned for the database.

Drop and Create the assembly and make to put the path of the assembly in plain text rather than scripting it from another environment as it would have been encoded and won't work on this server.

Technorati Tags: ,

Wednesday, April 15, 2015

Data Compression in SQL Server

By taking advantage of SQL Server's data compression feature, you can improve SQL Server performance without changing any application code. Compressing data reduces database storage, which leads to fewer I/O reads and writes. However, SQL Server consumes more CPU resources when it compresses and decompresses data. Data compression is currently supported in the Enterprise, Developer, and Evaluation editions of SQL Server 2008 and later.

Row compression doesn’t work on XML, BLOB and MAX data types instead you can create CLR functions to gzip them to reduce the storage space.

Saturday, August 30, 2014

SPARSE Columns and ColumnSets

I had a scenario where I had to load a csv file which had around 2000 columns. Then I started looking at the wide table feature which came as part of SQL Server 2008. A wide table can have 30,000 columns as opposed to a non-wide table which can have 1024 columns.

Having 30,000 or even 1,024 columns in a table is a lot of columns and design review needs to be done for these type of scenarios. In my scenario it is another system which generates this file and the business wants an ability to query it easily via a single table. More or less just for analysis purposes.

Sparse columns are designed to allow a relational database to store and process relatively unstructured data, where any individual entity may have a modest selection from a very wide set of attributes. This sort of data can be found frequently in scientific, pharmaceutical, and medical applications. EAV (Entity/Attribute/Value) storage techniques were engineered for such data; however, EAV data storage has proved to be somewhat inefficient in such areas as query speed and storage cost.

Sparse columns work well where a high proportion of the data in a column is NULL, because negligible storage space is used for the NULL representation. A table that is wide in theory can be made narrow in practice by implementing sparse columns, and the addition of filtered indexes provides effective searches on the sparse data. Sparse columns support the use of check constraints, as long as the constraints allow NULL values (a sparse column requirement).

Column sets provide a solution to the difficulties of efficient imports and exports of sparse data. The untyped XML representation that is generated for each row interacts directly with each sparse field. The XML field accepts inserts, and its data can be extracted and modified easily. This feature effectively supports certain types of serialized object data from various applications.

CREATE TABLE SPARSETABLE
(
 ID INT NOT NULL IDENTITY(1,1)
 ,FIRSTNAME VARCHAR(100) NOT NULL
 ,MIDDLENAME VARCHAR(100) SPARSE NULL
 ,LASTNAME VARCHAR(100) NOT NULL
 ,SPARSEDATASET XML COLUMN_SET FOR ALL_SPARSE_COLUMNS
)

INSERT SPARSETABLE(FIRSTNAME, MIDDLENAME, LASTNAME)
VALUES ('John','Daniel','Smith');
GO

INSERT SPARSETABLE(FIRSTNAME, LASTNAME)
VALUES ('Peter','Wilson');
GO


SELECT [ID]
      ,[FIRSTNAME]
      ,[LASTNAME]
      ,[SPARSEDATASET]
  FROM [SPARSETABLE]

Capture Metadata for Data Warehouses using SQL Server Extended Properties

SQL SERVER extended properties allows developers to load metadata information like description, Source etc on a table or column within a table. This will allow information to be documented and attached to SQL SERVER and also queryable.

--Add Extended Property for a table
EXEC sp_addextendedproperty 
 @name=N'Description', 
 @value=N'Dimension with the list of all products.' , 
 @level0type=N'SCHEMA',
 @level0name=N'dbo', 
 @level1type=N'TABLE',
 @level1name=N'DIM_PRODUCTS'

--Update Extended Property for the table
EXEC sp_updateextendedproperty 
 @name=N'Description', 
 @value=N'Dimension with the list of all available products.' , 
 @level0type=N'SCHEMA',
 @level0name=N'dbo', 
 @level1type=N'TABLE',
 @level1name=N'DIM_PRODUCTS'
GO

--Add Extended Property for a column
EXEC sp_addextendedproperty 
 @name=N'Description', 
 @value=N'Name of the Product.' , 
 @level0type=N'SCHEMA',
 @level0name=N'dbo', 
 @level1type=N'TABLE',
 @level1name=N'DIM_PRODUCTS', 
 @level2type=N'COLUMN',
 @level2name=N'PRODUCT_NAME'

--Update Extended Property for a column
EXEC sp_updateextendedproperty 
 @name=N'Description', 
 @value=N'Name of the Product' , 
 @level0type=N'SCHEMA',
 @level0name=N'dbo', 
 @level1type=N'TABLE',
 @level1name=N'DIM_PRODUCTS', 
 @level2type=N'COLUMN',
 @level2name=N'PRODUCT_NAME'
GO

--Query Extended Properties
SELECT objname, name, value
FROM fn_listextendedproperty(NULL, 'schema', 'dbo', 'table', default, NULL, NULL)

SELECT objtype, objname, name, value
FROM fn_listextendedproperty (NULL, 'schema', 'dbo', 'table', 'DIM_PRODUCTS', 'column', default);

Monday, February 17, 2014

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'xxxxxx.dll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7e7edcc6a6871fc7' or one of its dependencies. The system cannot find the file specified

  • Check whether the DLL is deployed successfully in GAC (Global Assembly Cache)
  • If not make sure that the DLLs are available in the following locations
    • D:\Program Files\Microsoft SQL Server\100\DTS\Binn (depending on the version of SSIS)
    • D:\Program Files (x86\Microsoft SQL Server\100\DTS\Binn (depending on the version of SSIS)
  • Also make sure that the DLL is compiled for the right platform (32-bit or 64-bit or both)

Wednesday, February 12, 2014

SQL SERVER CLR Integration

SQLCLR allows integration of .NET Framework CLR components in SQL SERVER. .NET CLR Assemblies reside and run from database rather than file system. SQL SERVER need to check only once during deployment. This boosts performance and reliability.

SQLCLR allows to write stored procedures, functions, triggers, user defined types and aggregates using variety of .NET Framework languages like C#, VB.NET etc.

When to use SQLCLR?

Don't use SQLCLR for querying data from SQL SERVER. It is better to use T-SQL for that. Instead use SQLCLR when you can't perform some tasks using native SQL functions like GZip Compression/Decompression, PGP Encryption/Decryption, complex string manipulations etc.

How to enable SQLCLR?

exec sp_configure 'clr enabled', 1;
GO
RECONFIGURE
GO

Cross Database Ownership Chaining in SQL SERVER

Consider a scenario where you have a view object in a database named "Database A" tries to access a table from "Database A" as well as a table from "Database B". In this scenario to run the view the user must also be a user in Database B along with Database A. If these databases are tightly linked, cross database ownership chaining can be used where user can access the table from Database B only through the view from Database A but doesn't have explicit permissions to query the table in Database B.

Steps to enable Cross Database Ownership Chaining

Set both Database A and Database B in the chaining as trustworthy.

ALTER DATABASE Database1 SET TRUSTWORTHY ON;
ALTER DATABASE Database2 SET TRUSTWORTHY ON;

Make sure that both Tables inside the Database A and Database B belong to the same owner.

Enable Cross Database Ownership Chaining. This can be done on whole instance level or specific databases.

For instance level

Exec sp_configure 'cross db ownership chaining', 1;
RECONFIGURE;

For database level

ALTER DATABASE Database1 SET DB_CHAINING ON;
ALTER DATABASE Database2 SET DB_CHAINING ON;

Tuesday, February 11, 2014

Are nested Windows groups supported as SQL Server 2008 logins?

Yes, it is completely supported in SQL Server 2008 irrespective of the instance running on Windows Authentication or Mixed mode Authentication.

Make sure the AD Groups are created as Security Groups rather than Distribution Lists. If not created as Security Groups, then Nested AD Groups will not be working.

Monday, September 03, 2012

Database Cannot be opened because it is version 706. This server supports version 661 and earlier

When I tried attaching a mdf file using SQL SERVER 2008 R2 I got the following error:

"Attach Database failed for Server "XXXXXX"

Database cannot be opened because it is version 706. This server supports version 661 and earlier

Solution

This is because the database I was trying to attach is SQL Server 2012. The only way to resolve this is to Generate Script from SQL Server 2012 then run it in SQL Server 2008 R2. This needs to be done for data too.

Tuesday, March 06, 2012

Using PATINDEX in SQL Server

Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types.

e.g. SELECT PATINDEX('%:%','22:30') will return 3 as the colon appears in that position.

Quite handy to figure out whether a pattern appears in the expression or not.

Saturday, February 18, 2012

How to configure SQL SERVER to accept remote connections?

STEP 1: Enabling TCP/IP

First we must tell SQL Server to listen on TCP/IP, to do this
perform the following steps:

1. Launch the SQL Server Configuration Manager from the "Microsoft SQL
Server 2008 R2 > Configuration Tools" Program menu
2. Click on the "Protocols for your SQL instance"
3. Right click on "TCP/IP" in the list of Protocols and choose, "Enable"

STEP 2: SQL Browser Service

Next, we have to determine if we want the SQL Browser service to be running or not. The benefit of having this service run is that users connecting remotely do not have to specify the port in the connection string.

STEP 3: Firewall..?

At this point you should be able to remotely connect. If you still
can't chances are you have a firewall configured on the computer where SQL
Server is running.

Make sure to add the port number you used for tcp/ip connection added to the exceptions list. The default port for SQL Server is 1433 unless you changed it to listen on another port

If you chose to use the SQL Browser service, you must also add
sqlbrowser service executable to the exceptions list as it listens on udp
port 1434.

Could not locate file 'FIelD' for database db in sys.database_files. The file either does not exist, or was dropped.

If you get the above error while truncating the transaction logs then either you haven't selected the proper database to run the script for truncating the logs or you haven't provided the correct logical log file name for the database.

Truncating Transaction Logs in SQL SERVER

Truncating transacation logs!!! Normally you need to find why your transactional logs are growing. The major reason would be that your transaction logs are not getting backed up.

First thing is to check your database recovery model and if you have it as 'FULL' and you deal with too many transactions within the day then start backing up your transaction logs otherwise change your recovery model to 'SIMPLE' (not suitable for databases dealing with large transactions)

Before you change the recovery model you need to truncate your logs.

USE [DatabaseName]
GO

ALTER DATABASE [DatabaseName] SET RECOVERY SIMPLE
GO

DBCC ShrinkFile('[Database log file Logical name]',100)
GO

Note: For Data Warehouse Databases, it is recommended to use 'SIMPLE' recovery model

Thursday, November 03, 2011

SSIS SQL Task - “Parameter name is unrecognized”

Scenario

You tried to set up a SSIS SQL Task and also assigned a parameter to that.

Solution
Make sure that you changed the Parameter name from 'NewParameterName' to 0.

Sunday, July 31, 2011

Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.

You may get the above error when trying to open the database diagram or trying to create a new diagram.

Solution

ALTER AUTHORIZATION ON DATABASE::DTLDW TO sa

or

Assign the Database owner to a valid login by right clicking on the database and choose properties > file.

Thursday, June 23, 2011

OLE DB provider "VFPOledb.1" has not been registered

I was trying to create a Linked Server on SQL SERVER 2008 R2 Server to connect to Foxpro database on a Windows 7 PC. I installed the Visual FoxPro 9.0 OLE DB provider and when I accessed the linked server, I got the above error.

Solution

Un-install the Visual FoxPro 9.0 OLE DB provider
Install the Provider for all users instead of current user and it will fix the problem.

Tuesday, February 08, 2011

The report definition is not valid. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition' which cannot be upgraded.

You may get the above error when trying to view a RDLC report using with the VS 2005 or VS 2008 viewer controls with 2008 schema.

When using local mode, you are using the same report processing engine that was shipped with SQL Server 2005. This engine does not understand the new report definition schema and attempting to load a report created with one of the new SQL Server 2008 authoring tools will result in this error.

Open the RDLC in VS2010 and use the v10 of the report viewer control to run the report.

RDL and RDLC

RDL - RDL stands for Report Definition Language

RDLC - Report Definition Language Client-side processing

RDL files are created by the SQL Server 2008 version of Report Designer. RDLC files are created by the Visual Studio 2008 version of Report Designer.

RDL and RDLC formats have the same XML schema. However, in RDLC files, some values (such as query text) are allowed to be empty, which means that they are not immediately ready to be published to a Report Server. The missing values can be entered by opening the RDLC file using the SQL Server 2008 version of Report Designer. (You have to rename .rdlc to .rdl first.)