Posts

Showing posts from 2011

Regular Expression for SQL Login Name / Database User Name

I am no expert in regular expressions but I had to work on a expression to validate sql login name and database user name to avoid sql injection as the login and database user creation proc uses dynamic sql.


^([A-Za-z0-9\._]*[\\]?[A-Za-z0-9\._]*)|((?!([A-Za-z0-9-\._])*\-\-)([A-Za-z0-9-\._])*)$


Satisfies the following condition:
letters, numbers(alpha numeric), a single backslash (\), hyphens (-), underscores (_) and periods (.) no more than one consecutive hyphen.

You can use the expression above in the .net code to do the validation in the UI.


This is the proc that acheives the same result:


IFOBJECT_ID('dbo.uspCreateLogin','P')ISNOTNULL
DROPPROCEDURE dbo.uspCreateLogin
go

CREATEPROCEDURE dbo.uspCreateLogin
(
@LoginName varchar(128)
)
AS

SETNOCOUNTON;


DECLARE
@Index INT,
@SQL VARCHAR(500),
@Invalid BIT;

--No two slashes in the login name
IFLEN(@LoginName)-LEN(REPLACE(@LoginName,'\',''))> 1
BEGIN
SET @Invalid = 1;
END;


--No two consecutive hypens in the name
IF @Invalid = …

New Values Clause Sql Server

Values clause in sql server is a new way to insert mulitple rows into the table one time.This is how to do it.


DECLARE @InputTable table (
  Name varchar(max),
 ID uniqueidentifier
)

INSERTINTO @InputTable
VALUES
('a','487671D5-1F05-4F2D-9A3B-5DC7EA3E046E'),
('b','487671D5-1F05-4F2D-9A3B-5DC7EA3E046E'),
('c','487671D5-1F05-4F2D-9A3B-5DC7EA3E046E')

select* from @InputTable;

------------------
Name ID
a 487671D5-1F05-4F2D-9A3B-5DC7EA3E046E
b 487671D5-1F05-4F2D-9A3B-5DC7EA3E046E
c 487671D5-1F05-4F2D-9A3B-5DC7EA3E046E

XPS M1530 NO DISPLAY / VIDEO BUT LIGHTS ON - Fixed

Image
OK, I don't know who said Women are better at baking than men.Being a man I don't know if I want to agree on that after baking the motherboard of dell xps m1530.

At times you have to see things you want to beleive especially when there are so many people faking many things on the web, baking a motherboard in oven is one of those.

After 2 years of purchase of the dell xps m1530, it started to show black screen at me when I turned on the machine.Lights come on and cd/dvd drive seems to spin for a second but no display, connecting to the external display did not help either.

Did lot of searching on the Internet and many people out there have the same problem like me.It seems that the problem is coming from the poor design of the motherboard with a faulty nvidia graphics chip. Surprisingly people were saying heating the graphics chip area with a hair blower seems to fix the problem for a while. I cleaned the fan, removed the old thermal paste and put the new one on but still th…

Simple Nant Build file - revert switch update

Nant you might all know is a powerful tool when creting builds.It offers lot of flexibility when it come to building projects.Nant along with subversion and wix can make your life easier to build your app.Here is a simple post that shows you how to use nant and get files.

Following script does
1.Clenup
2.Switch
3.remove unversioned files and directories
 4.revert
5.update

<?xml version="1.0" encoding="utf-8"?>
<project name="testscriptfile" default="build" basedir=".">

<property name="subversion.username" value="YourUserName" />
<property name="subversion.password" value="YourPassWord" />

<property name="subversion.projectpath" value="YoutPath" />
<property name="dir.project" value="yourPhysicalFilesPath" />

<property name="subversion.revision" value="-1" />
<property name=&qu…

StatusStrip missing windows vb.net c# mdi windows forms application

All of a sudden the status bar in our MDI windows forms application is lost when you resize the form smaller.

Here is the scenrario

MDI Parent -  Has a StatusStrip that contains 3 ToolStripLabels that has spring property set to false.

MDI Child - Has a StatusStrip that contains 1 ToolStripLabel that has spring property set to true.MDI Child form size is 1280 x 1024 (design time).

In the mdi child activate event of the mdi parent , the statusstrip from the mdi child is merged into the statusstrip of the mdi parent using the ToolStripManager.Merge method.

It seems the problem is "toolstriplabel" in mdi child spring is set to true and the width of the toolstriplablel is close to 1280(form width).So when you resize your mdi parent smaller than the design width of the toolstriplabel is trying to steal the 1280 width, as it is not available it went some where, also it is pushing the labels in the mdi area go out of the visible area.

To fix this problem ;
1.make the toolstriplabe…

Wix Build Error - Nant

error MSB4019: The imported project "C:\Program Files\MSBuild\Microsoft\WiX\v3.x\Wix.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

Update your wix projects to newer version when you upgrade wix on the machine.

Context 0x1b64e0' is disconnected : DirectoryEntry

Image
I started getting the exception below everytime I close my vb.net application.To fix this I had to either dispose the directory entry object after calling the ProcessDirectoryEntry in the for loop OR change "byval" to "byref" in the ProcessDirectoryEntry de parameter.

 For Each de As DirectoryEntry In delist
            ProcessDirectoryEntry(de)
    ''fix - de.dispose
Next
Sub ProcessDirectoryEntry(ByVal de As DirectoryEntry)
        ..
            ..
            ..
            ..
End Sub


Context 0x1b64e0' is disconnected.  Releasing the interfaces from the current context (context 0x1b6370). This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/apartments stay alive until the application is completely done with the RuntimeCallableWrappers that represent COM components that live inside them.

SQL Profiler and Management Studio batch files for launching

SQL Profiler
Sometimes you want to run your profiler as a different user than the user that is logged onto the machine and uses a template of your choice then the following lines in a batch file can help you.

SET SSMSEXE=C:\Program Files\Microsoft SQL Server\100\Tools\Binn\PROFILER.EXE
C:\WINDOWS\system32\runas.exe /user:Domain\otheruser /savecred "%SSMSEXE% /S spa /T mytemplate"

--
Launching Management Studio with Domain\OtherUser,windows authentication and dv_dev as default database.

SET SSMSEXE=C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe
C:\WINDOWS\system32\runas.exe /user:Domain\OtherUser /savecred "%SSMSEXE% -s spa -d DB_Dev -E -nosplash"
Tested under SQL Server 2008R2 only.

AT&T DSL Setup

OK, I switched from Uverse to DSL and opted for getting my own modem.But what I didn't realize is that only some modems are supported by AT&T.I bought Zyxel Prestige 600 Series 645 and tried to make it work with AT&T with no luck.Tried to logon to the device using telnet and set the user name and password,vci,vpi,multicasting and encapsulation.All the settings seems ok, I can see the modem stats but couldn't connect to at&t.

After days of struggling with the help of at&t representatives, I gave up and got SpeedStream 5100 modem along with Linksys WRT54g and was able to get on to the internet.Make sure you set the router to ppoe and set the username and password, plug the ethernet cable from the speedstream modem into the wan port and you should be able to get to the internet.