måndag 26 mars 2012

Relational database clean

Sometimes when developing you want to start over with a clean database. But if you have relational integrity, and using the Identity feature in SQL server, it could be a bit tricky.

However, this does it for you:

EXEC sp_MSForEachTable 'DELETE FROM ?'

EXEC sp_MSForEachTable 'DBCC CHECKIDENT (''?'', RESEED, 1)'


tisdag 20 mars 2012

T-SQL Split function

Split function to find the Nth word in a string

--select dbo.Split('abc,def', ',',2) --returns def

Create FUNCTION [dbo].[Split] (@fullString varchar(200), @separator char(1),@wordNo tinyint)
RETURNS VARCHAR(200) -- return_data_type.
declare @wordPart varchar(200),
              @sepPos int=0,
              @wordCount int = 1

while @wordCount <= @wordNo
      if @fullString = ''
            return null

      set @sepPos = CHARINDEX(@separator, @fullString, @sepPos) if @sepPos = 0set @sepPos = len(@fullString)
      set @wordPart = SUBSTRING(@fullString, 1, @sepPos)set @fullString = REPLACE(@fullString, @wordPart,'')
      set @wordCount = @wordCount +1


RETURN replace(@wordPart,',','')


tisdag 13 mars 2012

Branding SSRS, and make it look like an Intranet

If you want to enhance the user experience and feeling of a group of Reporting Services  reports and don't have SharePoint? You don't have to use the standard report library. Below is a screenshot where I use a tabular navigation looking a lot like a web site using just SSRS 2008 R2 standalone. The tabs are just actions that points to another report using the same header subreport. The user can navigate within the reports without having to go the the report library.

You could also brand use the web service interface to find reports and create your own branded SSRS portal using a SSRS report.

Access domain resources from other domain

Need to connect to a database, olap cube or other do main resource, but your computer is not logged in to the domain. Try the RUNAS command when launching your program.

For Excel:
RUNAS /user:domain\user /netonly "C:\Program\Microsoft Office\Office14\Excel.exe"

Cisco VPN x64 replacer

Cisco VPN client for 64-bit does not yet exist as far as I know. Try the Shrew client, http://www.shrew.net instead. Also, it doesn't cut your internet access.

SSIS, Oracle and x64

Originally posted by 2009 me at another blog.

SSIS, Oracle and x64

I hope I can spare someone the time I just spent to get this working...

The scenario is as follows:
We have SSIS 2008 installed on a windows 2008 x64 server and want to connect to a Oracle database and the standard drivers doesn't work. Something with version 7.3.3 requiring another set of drivers. Anyway, here is what I did. (You don't have to download the complete 1,87 GB package)

I chose to go through ODBC.

1. Download Instant Client Package - Basic (~40Mb) from Oracle (11g) for both 32 and 64-bit.

x64 found here:
and 32-bits found here:

2. At the same location, download Instant Client Package - ODBC (1Mb) for both 32 and 64-bits.

3. I started with the 64-bits install. Create a folder somewhere, i.e. C:\Oracle\InstantClient_64 and extract the files from the basic package (64-bit) to that folder. Extract the ODBC package (64-bit) to the same catalog. Open a commandprompt and run odbc_install. Be sure to start the prompt with administrator privileges.

4. Now we need som .ora files, sqlnet.ora and tnsnames.ora was enough for me. I copied them from another server. You will find lots of examples on the internet if you try searching google. I created a folder C:\Oracle\InstantClient_64\network\admin and placed them there.

5. Now we need to create some enviroment variables. Theese are shared between 32 and 64 bits enviroment. First add to the Path variable the directory you just created (C:\Oracle\InstantClient_64). Second create a new variable called TNS_ADMIN pointing to the location of you .ora files (C:\Oracle\instantclient_64\network\admin)

6. Run the ODBC-administrator with administrator privileges and try creating a system-dsn, it should work. The problem is that BIDS is a 32-bit application, so you can't see the 64-bits odbc sources from BIDS.

7. Create a folder somewhere, i.e. C:\Oracle\InstantClient_32 and extract the files from the basic package (32-bits) to that folder. Extract the ODBC package (32-bit) to the same catalog. Now here is the thing: open a commandprompt from C:\Windows\SysWOW64\cmd.exe and run odbc_install.exe. This installs this as a 32-bits driver.

8. Add the directory containing 32-bits package to the path variable (C:\Oracle\InstantClient_32)

9. Run 32-bits ODBC-administrator from: C:\Windows\SysWOW64\odbcad32.exe and verify that it works.

10. When you create the DSN, make sure you call them the same name in both 32 and 64 bits. Also, clear the username and make sure it's a system dsn.

11. Done.

Hope this will help someone, or me when this is long forgotten.