C# - initialize a variable

The term initialize means to assign an initial value. To initialize a variable is to assign it a value for the first time. You don’t know for sure what the value
of a variable is until it has been initialized.

February 1st, 2010 by Obe | No Comments »

Return a status or value from sp_start_job

In my procedure, I’m calling a job on a remote server and if this call fails, I would like the code to handle it accordingly. So if I get a return value or status of 0, the job started successfully. If 1, then it failed to start.

Now I can’t monitor the entire duration of the SQL job on the remote server, I’ll need another process for it.

The code to return a value or status from sp_start_job is as follow:


declare @rnt int

exec @rnt = msdb.dbo.sp_start_job @job_name = ‘JOB_NAME’

if @rnt = 1
begin
— code to handle the failure
end

April 30th, 2009 by Obe | No Comments »

iPhone 3G

The last time I touched an Apple, Inc. device was WAY WAY WAY back in the 3rd grade. Since high school, it has been nothing but PC and Microsoft Windows stuff.

Last weekend, I finally went out to purchase the Apple iPhone 3G. I wanted one since its release but at $600 a pop, I didn’t want to shell it out. When I learned about unlocking and jailbreaking, I was in.

So far, I’m loving the iPhone. I’ve always been a fan of BlackBerry or people in my profession call it a ‘CrackBerry’ because you never go anywhere with out it. I really wanted to the BlackBerry Storm but only Verizon carries it and I don’t like Verizon. I just recently found out that you can unlock that too but its cool, my iPhone is rocking.

Got over 25 apps and the best one thus far is the video recorder, which basically turn the iPhone digital camera into a digital camcorder.

http://www.quickpwn –> for jailbreaking. Then use yellowsn0w to unlock. Afterward, install Cydia.

April 22nd, 2009 by Obe | No Comments »

Creating Windows Clustered Resources

Over the past 3 weeks, I’ve built over 40 pairs of active/active cluster on Windows 2003. I’ve looked around the web, to see if someone has any type of script that will help me, but alas, everyone wants to show me how to PnC (point & click) my way thru the bullshit GUI.

Don’t get me wrong, I’m grateful for the GUI but when I’m setting up a crap load of A/A cluster servers, I want everything to be automated or as automated as possible. I ended up writing my own script. All you need to do is past in the correct variables and make sure you are on the server you are trying to create the shared folder. If not, you will definitely be in for a surprise!

Download Create clustered resources Version v0.1
April 14th, 2009 by Obe | No Comments »

changing sql services password

In my environment, I have over 100+ servers and every so many days, the account that runs SQL services are changed and it is a bitch to change it via point and click on 100+ servers.

Internally, there’s a tool that we all can use to reset password for services except that it isn’t friendly when you have active/active setup. The following script changes all that via the use of powershell. Of course, this is version 0.1. version 0.2 will be written in C# but that’s for later.

The script will create a table in a database, you will then need to populate the table with the physical server, SQL instance name (not the virtual name!!). Once that’s done, run the bottom portion of the script to output the powershell statement; which you will copy & paste into a powershell cmd screen.

Once you pasted it, powershell will start executing all the commands. After Powershell stop running the command, be sure to press ‘Enter’ to make sure that the last command actually get executed. I know it is still a bit manual but better then pointing and clicking thru 100+ servers to change a bloody password.

Download Change SQL services password Version v0.1
April 14th, 2009 by Obe | No Comments »

sql 2005 connection error

Error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

I have a server named: virtualA\virtualSQLA. This server was working fine a few days ago but after a server reboot, it was giving the above error message. I was able to connect via its virtual name (virtualA) and virtualA\virtualSQLA,1433 but not virtualA\virtualSQLA. After 20 minutes of looking around ….

Check that SQLBrowser service is running!!!!!!

April 10th, 2009 by Obe | No Comments »

finding a bunch of server’s ip address

get-content server.txt| foreach {
$strComputer = $_
$colItems = get-wmiobject -class “Win32_NetworkAdapterConfiguration” `
-computername $strComputer | Where{$_.IpEnabled -Match “True”}
foreach ($objItem in $colItems) {
write-host $strComputer ” : ” $objItem.IPAddress
}
}

in the server.txt file, one server per line and no extra space at the end of each server.

March 31st, 2009 by Obe | No Comments »

finding physical servername

For some reason, I have a problem remembering server name but don’t have any problem remembering SQL name instances. Maybe because I connect to the name instance more often then not. But when someone ask me what’s the physical servername of so and so SQL name instances, i’m lost.

a co-worker showed me a SQL function a few days ago that will tell you the physical servername of a SQL name instance:

select serverproperty(’ComputerNamePhysicalNetBIOS’)

I have to look around some more to see if this function will allow me to identify clustered nodes, be it active/active or active/passive.

March 18th, 2009 by Obe | No Comments »

order by asc for two (2) columns

a co-worker today asked if there was a way to insert data from one table into another but sort the columns by ASC for BOTH columns. For example, tableA has the following value:

rowid: 1,2,3,4
columnA: 3,7,1,6
columnB: 6,7,2,4

In his new table, he wants it to look like so (tableB):

rowid: 1,2,3,4
columnA: 1,3,6,7
columnB: 2,4,6,7

@ first, it should be easy right?

insert into tableB(columnA, columnB)
select columnA, columnB from tableA order by columnA, columnB

But that will only sort by columnA in asc. ColumnB will not be sorted at all. Instead I ended up doing:

insert into tableB(columnA)
select columnA from tableA order by columnA

The above statement gives me the 1st column in ASC order, now for the 2nd:

update v1 set v1.columnB=v.columnB from
(select ROW_NUMBER() OVER (order by columnB) as RowNumber, columnB
from tableA ) v
inner join tableB v1 on v.RowNumber=v1.Rowid

March 16th, 2009 by Obe | No Comments »

Finding filesizes

Yesterday, I was tasked w/ finding and identify the filesize of some files located in some directory. SQL doesn’t really have a function to do this and neither does a straight up DOS’ dir command.

Forunately, the Internet is a big place and someone wrote a one line syntax to do what I needed.

@echo off
for %%a in (E:\path\to\files\*.*) do (if %%~za GEQ 0 (echo %%~za %%a) ) )

I took this code, put it into a DOS .bat file, output the call to a .txt file, and then finally bulk inserting it into a table for SQL to crunch thru. With over 300GB of files in my directory, it took roughly 18seconds to complete the entire process.

I made some changes to what files were being stored in my directory and cut the process down to less than a second.

set @cmdListing = '\\path\to\batch\file\filesize_listing.bat > \\path\to\output_listing.txt'

exec xp_cmdshell @cmdListing

bulk insert dbname..fileSizesTable from 'E:\path\to\output_file\output_listing.txt'

After this, it was basically a select statement to find out if my kb column in the fileSizesTable column contains any 0.

February 6th, 2009 by Obe | 1 Comment »