Search This Blog

Monday, August 1, 2016

Monday, April 25, 2016

Just more ammo...

Not programming related, but useful to know... Recently, our PC's at my work has been randomly giving the error “User profile service failed the logon. User profile cannot loaded” message. If a user had logged onto the machine prior, they could log on, but if the person had not logged on before, they may or may not be able to log in. The below steps will resolve the issue.

  1. Run Windows Explorer with Administrative Rights (You may have to login as the local admin.)
  2. Browse to C:\Users
  3. Tap ALT, then Tools, then Folder Options.
  4. Select the View Tab
  5. Select Show hidden files, folders, or drives
  6. Click Ok.
  7. You should now see Default in the list of users.
  8. Right Click on the Default, select Properties.
  9. Click on Security
  10. Click on Advanced
  11. Click on Change Permissions
  12. Check the 'Replace all child object permissions with inheritable permissions from this object
  13. Click OK all the way out.
  14. It will prompt you to change permissions, click OK (or Yes).
  15. Log out and users should now be able to log in.



#14 above may be different, but that’s what my recollection of it is. 

Monday, August 19, 2013

Something useful for myself

Replacing a string in MS SQL.

REPLACE(OriginalField, "OldString", "NewString")

SELECT REPLACE(LastName, "Smith", "OriginalSmith")

This would change all occurrences of Smith in the LastName field to OriginalSmith. Smith becomes OriginalSmith, O'Smith becomes O'OriginalSmith, smithey becomes OriginalSmithey, and so forth. Microsoft has this on their site, but sometimes their terminology is too technical when looking for a quick answer.

Wednesday, August 7, 2013

Cursors in MS SQL

I'm always forgetting now to do a simple cursor in MS SQL, so here is the basic structure

DECLARE @field1 VARCHAR(10)
DECLARE @field2 VARCHAR(10)

DECLARE name_cursor CURSOR
FOR
SELECT field1, field2 FROM table WHERE this = 'that'

OPEN name_cursor

FETCH NEXT FROM name_cursor INTO @field1, @field2

WHILE @@FETCH_STATUS = 0
BEGIN
--DO WORK HERE
FETCH NEXT FROM name_cursor INTO @field1, @field2
END

CLOSE name_cursor
DEALLOCATE name_cursor

An alternate would be
WHILE @@FETCH_STATUS <> -1 -- -1 indicates beyond result set
BEGIN
IF @@FETCH_STATUS <> -2 -- -2 indicates row is missing
BEGIN
--DO WORK
FETCH NEXT
END
END

Tuesday, July 13, 2010

Effective Way to Remove CR LF in MySQL Query

I had a need to replace new lines in a query that was causing issues elsewhere in a process flow that I was working on. While removing the new lines in code would be easy, the problem was that they were needed to designate the end of a line in a file. So, I decided to remove them at the earliest possible step, and that is at the query. So, to do so, here is the statement...

REPLACE(REPLACE(userEnteredField, CHAR(10), ''), CHAR(13), '')

Since we are not sure if the input is inputing the new line as Carriage Return, Line Feed, or both, you first replace one, then replace the other. Most solutions I see posted have REPLACE(userEnteredField, CHAR(10) + CHAR(13)) which works if they are both present. The way done replaces, one or the other or both.

Thursday, May 6, 2010

I'm always searching for this...

To get the datakey on rowdatabound event for gridviews.


if (e.Row.RowType == DataControlRowType.DataRow)
{
string strY = GridView2.DataKeys[e.Row.RowIndex].Values[1].ToString();
}

The number 1 could be replaced with "KeyName" also.

Sunday, January 31, 2010

Getting Buffalo NFiniti wireless adapter working in linux

Recently, in getting the home dvr setup and working, it needed to be moved into another room. The best solution would be to run cat5 cable to that room, but to do it properly was going to be cumbersome, getting into the attic and running wires is not fun. The easy solution was to get wireless setup on the pc.

I searched and found a reasonably priced wireless-n card on Amazon. It was a Buffalo NFinity Wireless-N USB 2.0 adapter. This will hopefully give me the needed speed when viewing HD content on my PS3 in another room.

Well, the product arrives, and the process of getting installed under Linux began. Unfortunately it did not work "out of the box" so I started searching for what the card really was.... and in the end, it turns out to be a Ralink chipset card, and uses the RT3070USB drivers. They are downloadable from their website. This was like 3 or 4 hour search.

But the fun did not end there. Come to find out, the card may or may not have its "id" in the files provided from Ralink, so I had to modify the source to get it to work. Finally, after that, it worked like a charm.

Here are the steps I took to get this card working in Myth/Ubuntu 9.10...

1. Obtain drivers from Ralink (Ralink Driver Site).
2. Download the RT3070USB(RT307x) driver. In my case it was 2009_1110_RT3070_Linux_STA_v2.1.2.0.tar.bz2
3. Uncompress the resulting file with tar -xvzf 2009_1110_RT3070_Linux_STA_v2.1.2.0.tar (change as needed for the most current driver)
4. CD to the directory created
5. CD to the os/linux directory
6. Open the config.mk file in your favorite editor
7. In the config.mx file, change the HAS_WPA_SUPPLICANT=n and the HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n lines to have =y on the end instead of =n.
8. Save the file.
9. In a terminal window, type in lsusb. You should get a line that ends in Melco, Inc.
10. Notate the ID for the device, in my case it was 0411:015d
11. Open the usb_main_dev.c in your favorite editor.
12. Search for the id earlier in the form of 0x0411,0x15d.
13. If it is found, you are good to go, else add a line to the end of the list that looks like this.... {USB_DEVICE(0x0411,0x015d)}, /* Baffulo WIFI N USB */ If this line is not present, it will not detect and associate the device to the driver.
14. Save and exit out of your editor.
15. CD back to the main directory.
16. Make the driver, sudo make
17. Install the driver, sudo make install
18. To be on the safe side, at this point I restarted. When the pc came back up, I just used the wireless manager in GNome to setup the network connection.

Some futher issues I ran into was that for whatever reason, traffic was still trying to go out the eth0 and not the new wireless connection. I had to edit my /etc/network/interfaces file and comment out the auto eth0 line. At this point, when the pc starts, the wireless connects and works just fine. There were some other things that were specific to my setup with MythTV, but I'll leave those out unless someone asks.

Hopefully this helps someone.

Tuesday, January 26, 2010

Showing gridview when no records present

Here is an easy solution to get a GridView to show headers when there are no records to show.

Code snippet:

DataTable dt = getResults(); //getResults would query your datasource and return a datatable

if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.Databind();
}
else //part that generates the Gridview with headers only
{
dt.Rows.Add(); //adds blank row to table
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.Rows[0].Visible = false; //makes blank row invisible
GridView1.Rows[0].Controls.Clear(); //removes any controls for row
}

Friday, December 4, 2009

Weird Results with datatable.select

Ok,

Was working on a project today and need to get information from the database based off of an already completed query. I first did it by making a routine to run the query and build the select with a customer where statement, but hitting the db 300-400 times per incident was being slow and ineffective. So, I decided to just cut that down to one query and use a select on the resulting datatable.

I would get the results in a datatable, and make my expression.

My criteria was for the account, which was a number, and SQL syntax would be account = 1234567

That kind of worked, but would throw this error...

Min (274) must be less than or equal to max (-1) in a Range object.


After searching Google, I came across this post, Simillar error.

That post said to single quote the qualifier. So, I rewrote the expression to be account = '1234567' and it works.

Tuesday, December 1, 2009

Custom Link Buttons In Gridview

There have been times in my job, where a customized link button in a gridview was needed. While there are probably several ways to do this, the following is the best way to do it that I have found. In my case, I needed the link button to change text, and also change command name, based off of data from a query.

What I did was when creating the binding of the datasource to the gridview in codebehind, I added a datakey that I wanted to key off of.

gv.DataKeyNames = new string[] { "excluded" };


Then in the RowDataBound event, I have the following code within it. Basically it looks at the value I'm keying off of, and if it is a 1, then does one routine, else it does another. In the routine, it gets the LinkButton control from the cell, and then sets the text, forecolor, and command name.

if (Convert.ToString(gvEvents.DataKeys[e.Row.RowIndex].Values["excluded"].ToString()) == "1")
{
LinkButton lb = (LinkButton)e.Row.Cells[10].Controls[0];
lb.Text = "Include";
lb.ForeColor = System.Drawing.Color.Black;
lb.CommandName = "include";
}
else
{
LinkButton lb = (LinkButton)e.Row.Cells[10].Controls[0];
lb.Text = "Exclude";
lb.ForeColor = System.Drawing.Color.Black;
lb.CommandName = "exclude";
}

Sunday, November 29, 2009

Never wear the opposing teams color when approaching the mascot

USC's Cocky (Youtube Video)

Never too young to start learning lessons.

My Own DVR

First of all, just want to say that MythTV has several advantages, and several disadvantages, over what a cable/satellite company can offer you.

Advantages over Provider
1. No monthly cost
2. Various storage space options, not limited to their selections
3. Prioritization of recordings
4. Continuously being developed
5. Content is easily accessible for further editing
6. Customizable
7. You have access to code to make changes, if you wish.
8. Plugins provide access to DVD, Netflix, music, etc.
9. One server/backend can provide content to various frontends.

Advantages of provider
1. No upfront cost
2. It works out of the box.
3. No setup required
4. If it breaks, they replace it

So, while I do have two DVR's provided by local cable company, I chose to create a linux based DVR so that I could easily save programs that I wish, and if need be, burn them off onto CD.

Here is my setup.

Old Dell XPS system.
Pentium D
1 gig of ram
1TB Harddrive
Hauppage 1600 TV Tuner
MCE Remote/IR Blaster (as I could not get the Hauppage to work and it was included with the PC).

I have tried Mythbuntu 9.04, 9.10, 9.04 upgraded to 9.10, and 9.04 with MythTV upgraded to 0.22 and have come to the conclusion, atleast for now, that 9.04 that is setup and then upgraded to 9.10 was best for me.

So, I obtained the Mythbuntu CD through torrent and burned it off onto disk. It appears that this is no longer available on the Mythbuntu.org website, but a quick search of Google found this Mythbuntu 9.04

I plopped it into the computer, set it to boot from CD and let it load. I chose to install the system, and went with the default options, using the entire drive for my setup.

Once the install completed, you are given the option to go to schedules direct to setup your account and channel line ups. and then to setup MythTV. Upon choosing to setup MythTV, I was presented with a grey box that did nothing. I could not escape, etc. Apparently several other users have this issue as well from searches. But I was able to ALT-TAB to the console, hit Ctrl-C and exit out of it. For my setup, this was not a bad option as I had to do some additional downloads from what I had read.

Once the machine restarts, exit out of the front end and bring up a console. The below are the steps that I took to get the drivers installed and working for my Hauppage 1600. I used a Wiki guide for the basis, with some other steps that I had to take.

Stop the Backend
-sudo /etc/init.d/mythtv-backend stop

Install mercurial, headers, and build-essential
-sudo apt-get install mercurial linux-headers-`uname -r` build-essential

Download the drivers
-hg clone http://linuxtv.org/hg/v4l-dvb

Download the ncurses library (needed for menuconfig)
-sudo apt-get install libncurses5-dev

Change into the drivers library and make the drivers
-cd v4l-dvb
-sudo make rminstall
-sudo make distclean
-sudo make menuconfig (right arrow over and select exit, as the defaults should be fine).
-make (this will take a while)
-sudo make install

Download firmware and copy to correct location
-wget http://linuxtv.org/downloads/firmware/v4l-cx23418-cpu.fw
-wget http://linuxtv.org/downloads/firmware/v4l-cx23418-apu.fw
-wget http://linuxtv.org/downloads/firmware/v4l-cx23418-dig.fw
-sudo cp *.fw /lib/firmware
(Or if doing after a kernel upgrade... sudo cp cx18-firmware/*.fw /lib/firmware/`uname -r`)

Reboot machine

Once restarted, exit out of the front end.

Start the MythTV-BackEnd setup

Go through step 1.
For step 2, add new capture card. Select Analog V4L capture card, and press next a couple of times.
Then scroll down, and select the Analog card, and change it to IVTV MPEG-2 encoder card. If I did not do it this way, the card would not work for some reason. Not sure if it is a bug in MythTV or the drivers. This differs from the Wiki guide I followed.

Add the HDTV tuner as a DVB DTV capture card (v3.x), and select recording options, and change max recordings to 1.

Add your video sources in step 3 that you created for schedules direct.

Input connectors, you will need to connect the card to the video source and scan for channels.

This is where I ran into issues and was not able to find a good guide/how to. And all posts for people that say they got it to work, never give details on how they did it.

I had a cable box that I wanted to control with the system, and most guides that I came accross were for DishTV. Hopefully this will help someone.

If you just have basic cable, or over the air, what you will need to do in Step 4 is to select appropriate tuner, the 'analog' for basic cable, or DVB for 'ota'. Then choose the appropriate channel lineup. For basic cable, I called mine Basic Cable, High Def for the ota channels, and Digital Cable for my cable box setup, which I will cover later.

Once the channels are scanned, you can exit out and let the mythfilldatabases run to get your channels and such setup.

Now, if you want to control a cable box, the setup needs to be a little different.

For your connector, you will chose the 'analog' card, and your digital channel lineup. You will not need to scan for channels though. Make sure your tuner preset is set to 3, or appropriate channel, and then choose fetch channels from source. It will appear to be doing nothing, but if you CTRL-Tab to the console, you should see it downloading the channels.

Once completed, set your starting channel to something like NBC, FOX, etc. Mine defaults to 1 which is an on-demand channel and not the greatest choice.

Exit out and let the mythfilldatabase do its thing.

Restart the frontend and verify that you can watch tv. Channel changing may not work if you have an external box setup. This is because there are some additional steps to take.

If you have a settop box to control, the following steps worked for me. I could never get the hauppage remote to work, so went with an MCE that I had that came with the PC originally that I had never used.

To get it to work, close out of the frontend, and enter the Mythbuntu Control Center. Select the Infrared section, and select the Remote that you have, and the blaster that you have. Apply the changes and let it do its thing.

Now you will need to create a channel change script. To do so, the following worked for me. In a console, open vi (or vi channel-change.sh) and you should have a blank document. You can use your editor of choice for this.

The following script worked for me...

#!/bin/bash
REMOTE_NAME=SAE8000
for digit in $(echo $1 | sed -e 's/./& /g'); do
irsend --device=/dev/lircd SEND_ONCE $REMOTE_NAME $digit
sleep 0.5
done
irsend --device=/dev/lircd SEND_ONCE $REMOTE_NAME select
sleep 1.0
irsend --device=/dev/lircd SEND_ONCE $REMOTE_NAME exit
sleep 1.5
irsend --device=/dev/lircd SEND_ONCE $REMOTE_NAME exit

REMOTE_NAME=SAE8000, this will need to match your settop box/remote from your provided. In my case I have a Scientific Atlanta 4250C and the SA8000 remote works for it. The middle for loop just sends the channel number to the settop. Afer the loop, it then sends a select, which is like the enter for the remote. it waits a second, then sends an exit which will clear the guide faster, and then waits another 1.5 seconds and sends another exit. This is for the Enhanced/Startover menu that some of our channels have. You can customize this script to meet your needs. Save the file and exit out of the editor. Now do a 'sudo chmod +x channel-changer.sh' to make it executable. Now copy it to /usr/local/bin with 'sudo cp channel-change.sh /usr/local/bin' This will make it available to the backend to change channels and not have a permissions issue.

To test, if you are in the directory of the script, run './channel-change.sh 54' and it should change the converter to channel 54 for you. Once verified that this works, you can go back into the backend and choose your channel source (step 4) and for the external channel change script, type in the full path/name for the script.

You can now exit out of the backend, no need to run mythfilldatabase, you can cancel that, and then start the front end and ensure that you can change the channel while watching TV. If the path/file name were entered wrong, i.e. it cannot find it, it will bring up a black screen and exit to the menu.

At this point, 9.04 with MythTV 0.21 should be setup and ready to watch/record tv. I chose to upgrade to 0.22 and found that the best way to do this was to upgrade MythBuntu to 9.10. Why not start with that? Well, there is a nasty bug in MythTV 0.22 that will not scan channels on the analog card. By installing and setting up 0.21 first, you can avoid that as the files will already be created/database filled in and the channel scan will be unnecessary. I tried just staying with 9.04 with an update to MythTV 0.22 and initially got an error that the frontend and backend where different version. I finally did a full upgrade to 9.10 and things worked normally. To keep up with MythTV updates, you can install the Auto-Builds package.