Owner: calliCODE++; /* Where abstract becomes concrete */ URL:http://www.callicode.com/MyBlogs/tabid/53/Default.aspx Join Date: Fri, 24 Aug 2007 12:24:38 -0500 Rating:0 Site Description: Articles, tips, code snippets taken from my life as Software Developer. Site statistics:Click here
Creating COM+ applications using .NET 2007-08-24 00:00:00 I remember that some time ago I had the need to interact with a library written in .NET from MS SQL 2000. Creating
a COM+ object using managed code was the first thing that came to my mind (I had done it before using C++). I googled it for a little bit but couldn't find the right way to get this done and since I was really in a hurry ended up creating a simple console application that was called using xp_cmdshell.
Today I had the time to revisit this issue and this time in less than 1 minute the right article came on top of my search results: Microsoft Enterprise Services allows you to create Microsoft COM+ applications using the .NET Framework.
This is the article that explains this process in details:http://support.microsoft.com/kb/306296
How to invoke COM applications from SQL?http://www.sqlservercentral.com/columnists/dasanka/callingcomfromtsql.asp
How to select unique key values from a "key pool" 2007-08-13 23:00:00 Imagine the following scenario: The table defined below is populated with "key values" available to a given application. These values are generated by other application and inserted in batches from time to time into this "key pool" table.
/* Create table */CREATE TABLE [KeyPool]([KeyPoolId] [int] IDENTITY(1,1) NOT NULL,[Key] [varchar](30) NOT NULL,[IsUsed] [bit] NOT NULLCONSTRAINT [PK_KeyPool] PRIMARY KEY CLUSTERED ([KeyPoolId] ASC))
/* Insert test values */INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00001',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00002',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00002',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00003',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00004',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00005',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00006',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00007',0)
How you select a unique
key from
How to convert an object to a string (and back) 2007-07-29 23:00:00 Shows how to convert an object to a byte array using the binary formater and then encoding the resulting byte array to a Base64-encoded System.String.
Select top n rows using a column for grouping and a different column as selection criteria. 2007-07-27 23:00:00 Today I was asked to look into an interesting task that was keeping busy one of my colleagues for a while. It's such a common task that I'm wondering how come I was never presented with something similar before.Let's use an example to better illustrate the task on hand. Imagine you have a notification system that runs daily and creates a list of different
events for what individual users need to be notified. This table represents the notification list resulted from the daily run:UserId EventId------------------- 1 1 1 2 1 3 2 2 3 2 3 4 3 5 4 2 Now a new requirement comes up: All events will be assigned a priority and the users can only received 2 notifications a day for the events with the highest priority.This table represents our Events and their Priority (the bigger the number the highest is the priority):EventI Read more:Select
, selection
, criteria
Creating COM+ applications using .NET 2007-08-24 00:00:00 I remember that some time ago I had the need to interact with a library written in .NET from MS SQL 2000. Creating
a COM+ object using managed code was the first thing that came to my mind (I had done it before using C++). I googled it for a little bit but couldn't find the right way to get this done and since I was really in a hurry ended up creating a simple console application that was called using xp_cmdshell.
Today I had the time to revisit this issue and this time in less than 1 minute the right article came on top of my search results: Microsoft Enterprise Services allows you to create Microsoft COM+ applications using the .NET Framework.
This is the article that explains this process in details:http://support.microsoft.com/kb/306296
How to invoke COM applications from SQL?http://www.sqlservercentral.com/columnists/dasanka/callingcomfromtsql.asp
How to select unique key values from a "key pool" 2007-08-13 23:00:00 Imagine the following scenario: The table defined below is populated with "key values" available to a given application. These values are generated by other application and inserted in batches from time to time into this "key pool" table.
/* Create table */CREATE TABLE [KeyPool]([KeyPoolId] [int] IDENTITY(1,1) NOT NULL,[Key] [varchar](30) NOT NULL,[IsUsed] [bit] NOT NULLCONSTRAINT [PK_KeyPool] PRIMARY KEY CLUSTERED ([KeyPoolId] ASC))
/* Insert test values */INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00001',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00002',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00002',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00003',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00004',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00005',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00006',0)INSERT INTO [KeyPool] ([Key], [IsUsed]) VALUES ('KEY00007',0)
How you select a unique
key from
How to convert an object to a string (and back) 2007-07-29 23:00:00 Shows how to convert an object to a byte array using the binary formater and then encoding the resulting byte array to a Base64-encoded System.String.
Select top n rows using a column for grouping and a different column as selection criteria. 2007-07-27 23:00:00 Today I was asked to look into an interesting task that was keeping busy one of my colleagues for a while. It's such a common task that I'm wondering how come I was never presented with something similar before.Let's use an example to better illustrate the task on hand. Imagine you have a notification system that runs daily and creates a list of different
events for what individual users need to be notified. This table represents the notification list resulted from the daily run:UserId EventId------------------- 1 1 1 2 1 3 2 2 3 2 3 4 3 5 4 2 Now a new requirement comes up: All events will be assigned a priority and the users can only received 2 notifications a day for the events with the highest priority.This table represents our Events and their Priority (the bigger the number the highest is the priority):EventI Read more:Select
, selection
, criteria
How to reset the MySQL root user privileges on Windows 2007-10-23 00:00:00 Follow these steps to reset the MySQL
root user privileges on Windows
:
1- Stop the MySQL service
2- Open a command prompt and run the following command:
D:MySQLMySQL Server 4.1in>mysqld-nt --skip-grant-tables
3- Open a new command prompt and connect to the mysqld server with this command:
D:MySQLMySQL Server 4.1in>mysql -u root
4- Issue the following statements in the mysql client:
mysql> FLUSH PRIVILEGES;
mysql> USE mysql;
mysql> REPLACE INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
mysql> REPLACE INTO user VALUES ('%','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
mysql> quit;
5- Open the windows task manager and kill the process with name
How to convert from SAS date format to SQL datetime 2007-11-01 00:00:00 I was asked how to convert SAS dates to SQL
datetimes. Most of the time all it takes is simple Google search to find the solution for requests like this one, well not this time.
I created a function that do the conversion and wanted to share it with you all :-)
This is how you use the function:
select dbo.ConvertSASDate('12DEC2006:15:15:11.000')
Here is the function:
SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO
CREATE FUNCTION dbo.ConvertSASDate( @SASDate varchar(50))RETURNS datetimeASBEGIN
-- convert SAS format
to european datetime format (dd mon yyyy hh:mm:ss:mmm) DECLARE @EuropeDate varchar(50) SET @EuropeDate = substring(@SASDate, 1, 2) -- dd + ' ' -- space + substring(@SASDate, 3, 3) -- mon + ' ' -- space + substring(@SASDate, 6, 4) -- yyyy + ' ' -- space + substring(@SASDate, 11, 2) -- hh + ':' -- : + substring(@SASDa
SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified 2007-11-27 23:00:00 This error kept me busy all morning and part of the afternoon:
An error has occurred while establishing a connection to the server. When connecting to SQL
Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces
, error: 26 - Error Locating Server/Instance Specified)
This error seems to be affecting more developers - according to some forums and blogs - but none of them had a solution.
After trying some workarounds I finally found one that worked: The SQL port - 1433 - needs to be included as part of Data Source on the connection string:...Data Source=mysqlserverinstance1,1433;...
That did it for me.
Note that the error was happening when connecting to a SQL Server 2000 from a .NET 2.0 web application.
I'm not sure the real cause of this problem or why it was happening in the first place.
I also posted my workaround on the following forums:http://blogs.msdn.com/sql_protoc
Reading about Design Patterns 2008-02-09 23:00:00 Last week I found this site on digg.com it caught my attention and since I was busy at that moment I saved it on my del.icio.us bookmarks to check it out later.This Sunday I had an extra free time - since there is not much to do outside when it feels like -28C outside - and decided to go back to the article.Well this is excellent reference material for any developer/software architect. The video tutorials are excellent and guide you step by step in understanding and implementing the given pattern.Here is the link to the article: -patterns-and-tips Read more:Reading
, Patterns
, Design Patterns
Say goodbye to HTML tables 2008-01-29 23:00:00 This month while involved on the redesign of a very popular website I decided not to use HTML tables anymore - or at least avoid its use as much as possible. Ten years ago - when I started building websites - Tables were your friends not your foe. Along came CSS and the idea of separating the content from the way it is presented. CSS is been around for a while and almost all the sites currently it somehow but do they use it well? Check out CSS Zen Garden and decide if your site allows being re-skinned as much as this site.It’s been an excellent experience and I’ll be posting some tips about how to build CSS-friendly sites in the future.
How to enable CURL for PHP on Windows 2008-01-07 23:00:00 These are the steps that worked for me:Uncommented the line "extension=php_curl.dll" in php.ini file.Copied libeay32.dll and ssleay32.dll to C:\WINDOWS\system32. Note that these two dlls can be found on the PHP folder under the dlls folder. Adding this folder to the Windows
PATH variable should also work. You can use this simple test script - which retrieves and displays yahoo.com homepage - to verify that CURL is now working:
About the error: The name ... does not exist in the current context 2008-07-03 00:00:00 When you try to compile in .Net 2.0 (and up) web pages created using .NET 1.1 and automatically migrated by Visual Studio you may receive an error
like this: The name "SampleControl" does not exist
in the current context.
If you try to declare the control in your code-behind file you will receive the following error: The type "SamplePage" already contains a definition for "SampleControl".
The s