0

Finding StoreGeneratedPattern value in EdmProperty in T4 Template

Posted by Tim on May 11, 2011 in .NET Framework, C#, SQL Server

If you need to find out if a primary key in your conceptual model which is using the Identity value from the property StoreGeneratedPattern, you can use the following code: (NOTE: This is used within a T4 template) string inputFile = @"..\EntitiesModel.edmx"; EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile); string annotationNamespace = "http://schemas.microsoft.com/ado/2009/02/edm/annotation"; foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e [...]

Tags: , ,

 
0

Determing SQL Server Table Size

Posted by Tim on September 3, 2010 in SQL Server

This is a bit of code I found that determines the size used by each table in your database. Make sure you run DBCC UPDATEUSAGE first to correct any incorrect stats (pages etc) on your tables. DBCC UPDATEUSAGE (YOUR DATABASE NAME) DECLARE @TableName VARCHAR(100)    –For storing values in the cursor –Cursor to get the [...]

Tags:

 
0

You receive a “The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect” exception when using NVarchar parameters with Sqlclient

Posted by Tim on August 26, 2010 in .NET Framework, SQL Server

The problem I got the following random error: You receive a “The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect” exception when using NVarchar parameters with Sqlclient The Solution Its a known bug with the .Net SqlClient Data Provider.   If you have a field in the database of type nvarchar(max) [...]

Tags: , ,

 
0

Clean your SQL Server database!

Posted by Tim on December 23, 2009 in SQL Server

Here are some lines of code that can help clean your database from test data so you can start over with a fresh canvas. /* Disable constraints and triggers (if any) */ exec sp_MSforeachtable ‘ALTER TABLE ? NOCHECK CONSTRAINT ALL’ exec sp_MSforeachtable ‘ALTER TABLE ? DISABLE TRIGGER ALL’ /*Perform delete operation on all table for [...]

Tags: ,

 
0

Finding the Length of an Image Field in SQL Server

Posted by Tim on November 19, 2009 in SQL Server

Problem: I need to know the size in bytes of an image stored in an Image field in SQL Server Solution: SELECT DATALENGTH(column) FROM table

Tags:

 
0

Data in SSRS Report Header

Posted by Tim on September 15, 2009 in Reporting Services, SQL Server

Here is a tip for displaying data from data-sets into the Page Header/Footer of a SSRS report.   Traditional the hacky way of performing such tasks is to have a hidden text-box in the body of the report with the respective data-set field value.   You can then get the value of this text-box in your page [...]

Tags:

 
1

Split Function for T-SQL using XML

Posted by Tim on July 29, 2009 in SQL Server

Here is some sample code to split a string and return the results via a table. CREATE FUNCTION [dbo].[split] ( @del char(1), @str varchar(max) ) RETURNS @tResult TABLE ( val varchar(max) ) AS BEGIN declare @xml xml set @xml = N’<root><r>’ + replace(@str,@del,’</r><r>’) + ‘</r></root>’ insert into @tResult(val) select r.value(‘.’,’varchar(max)’) as item from @xml.nodes(‘//root/r’) as [...]

Tags:

 
0

The specified ‘@subsystem’ is invalid

Posted by Tim on April 8, 2009 in SQL Server

If you get the following error: Create maintenance plan failed. The specified ‘@subsystem’ is invalid (valid values are returned by sp_enum_sqlagent_subsystems). (Microsoft SQL Server, Error 14234) Just install Integration Services (just a little job…) and reboot. References: http://support.microsoft.com/kb/909036/en-us

Tags: ,

 
0

Selecting a row position within a SELECT query

Posted by Tim on March 11, 2009 in SQL Server

I want to get the third row in a result set from the following: ID   Name 1   A 2  B 3  C 4 D You can acheive this by using the ROW_NUMBER() rank function using SQL Server 2005/2008.   The following code will return the 3rd record. create table #temp ( ID int, [Name] nvarchar(50) ) [...]

Tags: ,

 
0

SQL Server Express 2008 Maintenance Script

Posted by Tim on November 14, 2008 in SQL Server

The issue I have with SQL Server Express Edition 2008 is that the SQL Agent is disabled and according to Microsoft, this has been disabled on purpose.   So, how do we schedule jobs to do such tasks as Rebuilding Indexes, Full-text Catalogs etc?   I use the Task Scheduler on Windows 2008 Server that executes a [...]

Tags: ,

Copyright © 2008-2012 Codelab Blog All rights reserved.
Desk Mess Mirrored version 1.9.1 theme from BuyNowShop.com.