Skip to main content

Posts

Showing posts from 2012

Display Chinese Characters in SQL

-- TO REMOVE ALL UNWANTED TERMS FROM THE STRING AND DISPLAY CHINESE , RUSSIAN AND ENGLISH, DUTCH, GERMAN....  CHARACTERS   CREATE PROCEDURE   [dbo] . [XXX]           @UserName nvarchar ( 32 )         AS         BEGIN           -- SET NOCOUNT ON added to prevent extra result sets from           -- interfering with SELECT statements.           SET NOCOUNT ON ;            Declare @strText as nvarchar ( 500 )        select @strText = Replace ( SearchText , N'^' , N'' )        from TABLENAME   where UserName = @UserName                    While PatIndex ( N'%[^a-z^A-Z^0-9^А-Я^а-я^ 诶 - 贼德 ^ 一 - 龥 ]%' , @strText ) > 0           BEGIN                   Set @strText = Stuff ( @strText , PatIndex ( N'%[^a-z^A-Z^0-9^А-Я^а-я^ 诶 - 贼德 ^ 一 - 龥 ]%' , @strText ), 1 , ' ' )                      END                      select @strText as UserKeyword              END

Reasons Not to Mess with Children

A  little girl was talking to her teacher about whales.   The teacher said it was physically impossible for a whale to swallow  a human because even though it was a very large mammal its  throat was very small. The little girl stated that Jonah was swallowed by a whale. Irritated, the teacher reiterated that a whale could not swallow  a human; it was physically impossible.  The little girl said, 'When I get to heaven I will ask Jonah.' The teacher asked, 'What if Jonah went to hell?' The little girl replied, 'Then you ask him.'     A  Kindergarten teacher was observing her classroom of children  while they were drawing. She would occasionally walk around  to see each child's work. As she got to one little girl who was working diligently,  she asked what the drawing was. The girl replied, 'I'm drawing God.'   The teacher paused and said,  'But no one knows what God looks like.' Without missing a beat, or looking up from her

Catching Unhandled Exceptions [C#]

This example shows how to manage all exceptions that haven't been caught in the try-catch sections (in Windows Forms application). The  UnhandledException event  handles uncaught exceptions thrown from the main UI thread. The  ThreadException event  handles uncaught exceptions thrown from non-UI threads. [C#] static void Main() { Application .EnableVisualStyles(); Application .SetCompatibleTextRenderingDefault( false ); Application . ThreadException += new ThreadExceptionEventHandler (Application_ThreadException); AppDomain .CurrentDomain. UnhandledException += new UnhandledExceptionEventHandler (CurrentDomain_UnhandledException); Application .Run( new Form1 ()); } static void Application_ThreadException( object sender, ThreadExceptionEventArgs e) { MessageBox .Show(e.Exception.Message, "Unhandled Thread Exception" ); // here you can log the exception ... } static void CurrentDomain_UnhandledException( object sender, UnhandledException

Adding a linked Server using the GUI

Adding a linked Server using the GUI There are two ways to add another SQL Server as a linked server.  Using the first method, you need to specify the actual server name as the “linked server name”.  What this means is that everytime you want to reference the linked server in code, you will use the remote server’s name.  This may not be beneficial because if the linked server’s name changes, then you will have to also change all the code that references the linked server.  I like to avoid this method even though it is easier to initially setup.  The rest of the steps will guide you through setting up a linked server with a custom name: To add a linked server using SSMS (SQL Server Management Studio), open the server you want to create a link from in object explorer. In SSMS, Expand Server Objects -> Linked Servers -> (Right click on the Linked Server Folder and select “New Linked Server”) Add New Linked Server The “New Linked Server” Dialog appears.  (see below).