I had a bit of trouble finding this, and I see other people asking it, so here it goes:
I found the key was using the imageAttributes class. Basically set the color key to the color you are using to represent the transparent area, and use one of the drawImage calls that accepts an imageAttribute parameter...
Imports System.Drawing.Imaging
' and in a sub somewhere:
Private mImageAttributes As New ImageAttributes
mImageAttributes.SetColorKey(Color.FromArgb(0, 220, 20, 255), Color.FromArgb(0, 220, 20, 255))
Dim imageRectangle As New Rectangle(pX, pY, pBitmap.Width, pBitmap.Height)
e.Graphics.DrawImage(pBitmap, imageRectangle, 0, 0, pBitmap.Width, pBitmap.Height, GraphicsUnit.Pixel, mImageAttributes)
Tuesday, April 7, 2009
Sunday, April 5, 2009
SQL Server Migration - The easy way
I have had the experience of moving an instance of SQL Server from one machine to another a few times and tried a few different ways of doing so. In simple cases, it can be as simple as scripting a few logons, and restoring backups on a new machine. Sometimes it is a little more involved if replication is involved. The scenario I am covering here is where you would like to replace a machine with SQL and move it to a new machine. I have used this method successfully to move a SQL instance from windows server 2003 to another 2003 box and even from a windows server 2003 box to a 2008 one. Here is an example of what has worked for me, where I want to replace a server named MainServer with a Server called NewBox
- Backup all databases on MainServer.
- On NewBox, install the same version of SQL as on MainServer, and make sure it has the same service pack if any. ALSO, make sure that the data and log paths on NewBox match that of MainServer (this is important).
- Shut down the SQL server on MainBox and set the SQL server service to start up manually as opposed to automatic. Rename MainServer to MainBox-Old or some other name and reboot.
- Rename NewBox to MainServer and reboot. Now shut down SQL Server.
- Now, since we had the data and log paths set the same on the new server, all we need to do is copy the data and log directories over to the new machine in place of the current install. So, for example, if I had a default install where the logs and data are in the same path (C:\Program Files\Microsoft SQL Server\Data\MSSQL.1\MSSQL), I would find the MSSQL folder for my instance that has the Backup, Data, LOG, etc subfolders and rename that folder MSSQL.OLD (as a fallback). I would then copy over the MSSQL folder from my old instance to the same location as MSSQL.OLD and then I can simply restart the SQL Server and it should start with all logons, replication, and settings of the SQL instance prior to the move.
Sunday, March 15, 2009
unable to find manifest signing certificate in the certificate store
I got this sweet error on my build server today, shortly after enabling signing of my project. I saw many different solutions on the web for this, but most of them involved removing the signature from the project, which I did not want to do. In the end, I ended up installing visual studio express on my build machine and opened up the project. What finally fixed it was going to my project properties -> signing tab, clicked the 'select from file...' button, browsed to my strong name key, and hit OK. Here it asked me for my password on the file (which I may have gotten wrong on the first build on this machine), I entered that, and then it was happy. I assume this action put the certificate into my store as it was building it fine after that.
Thursday, March 12, 2009
LINQ passing query results
Wow, first off, I need a better way to post code to the blog. I noticed this guy has rigged up a way and I will give it a try when I have some time: Please make a note blog
In the meantime I put my code snippet as a crappy image. The problem that I had being a fairly new Linq user was, what if I want to pass the results of a LINQ query to another method, or based on some logic in an if statement, do something different for the query, how can I declare it so I can pass it or use it and assign it based on logic. I found that in the case where I know what I am getting back from my query, then I can declare an Ienumerable of my type and assign it or pass it as I please. In this case I had a query return squares in a sudoku puzzle. You can see below how to declare and then assign the results of one of two linq queries.
In the meantime I put my code snippet as a crappy image. The problem that I had being a fairly new Linq user was, what if I want to pass the results of a LINQ query to another method, or based on some logic in an if statement, do something different for the query, how can I declare it so I can pass it or use it and assign it based on logic. I found that in the case where I know what I am getting back from my query, then I can declare an Ienumerable of my type and assign it or pass it as I please. In this case I had a query return squares in a sudoku puzzle. You can see below how to declare and then assign the results of one of two linq queries.
Wednesday, March 11, 2009
SSPI Handshake errors
My initial purpose for this blog was to post things that caused me trouble at work that I could not find answers to what I was looking for on google. One of the things that has cropped up lately is some SSPI handshake errors for users connecting to a central SQL Server. The first most obvious cause of this that I have found is when a user has a basic change in their active directory user account. Sometimes their account gets locked out from too many failed password attempts or they change their password, and until this replicates to all sites, they can get handshake errors. Failing that the event log usually shows evidence of issues communicating with servers in regards to these issues. The best resource I have found when troubleshooting this issue is the sql protocols blog. There is one specific page that I can't seem to find again that has several different scenarios where this can occur and how to troubleshoot it. I think one of the keys to this is understanding Kerberos.
The ultimate brownies?
Totally off topic here, but..... I have been looking for a brownie recipe that is nice and chewy and moist just like Betty Crocker. The only difference is that I want to make them myself because they taste better when you make them. Anyone know how to nail these down like Betty? Mine keep ending up like hard plates.
Sunday, March 1, 2009
WCF Host and Client in same assembly
A few weeks ago I decided to write a networked, multi-player version of Sudoku. One of the first things I had to decide to tackle was how the client and server should communicate. I had done something similar in the .net framework 1.1 using sockets and that was my first thought, however I had heard of .NET remoting and thought that was worth looking into. After some research, I found that the most current practice for client/server communication was to use WCF, part of the .NET Framework 3.0 and thereafter. I could not believe how simple this ended up being, and it broke down to a few lines of code in the end. First I had to put this section in my app.config:

For service name I just put the name of my class with the namespace, I gave the name of the service the same name as my class, and as my contract, I created an interface that has to be present in the server and client, but in my case my assembly could be either. The interface just specified which methods could be called on my server class, and then my server class just implemented that interface. For the server I added a thread to my user interface and when a user chose to host a game it just did this:
mHostThread = New Threading.Thread(AddressOf StartHost)
mHostThread.Start()
And startHost simply did this:
mPuzzleHost = New ServiceHost(GetType(PuzzleServer))
mPuzzleHost.Open()
Having this in a thread allowed the person hosting the game to also join as a client. Then to join the game (server) as client all I had to do was this:
Dim puzzleFactory As ChannelFactory(Of IPuzzleServer) = New ChannelFactory(Of IPuzzleServer)("PuzzleServer")
puzzleFactory.Endpoint.Address = New System.ServiceModel.EndpointAddress("net.tcp://" & frm.IP & ":3315/PuzzleServer")
Try
mPuzzleProxy = puzzleFactory.CreateChannel
mPlayerId = mPuzzleProxy.JoinGame(frm.PlayerName, frm.PlayerColor)
Catch ex As Exception
MessageBox.Show("Could not connect to host '" & frm.IP & "'. Reason: " & ex.Message)
Exit Sub
End Try
I hope that makes sense, if you have any questions feel free to email me.

For service name I just put the name of my class with the namespace, I gave the name of the service the same name as my class, and as my contract, I created an interface that has to be present in the server and client, but in my case my assembly could be either. The interface just specified which methods could be called on my server class, and then my server class just implemented that interface. For the server I added a thread to my user interface and when a user chose to host a game it just did this:
mHostThread = New Threading.Thread(AddressOf StartHost)
mHostThread.Start()
And startHost simply did this:
mPuzzleHost = New ServiceHost(GetType(PuzzleServer))
mPuzzleHost.Open()
Having this in a thread allowed the person hosting the game to also join as a client. Then to join the game (server) as client all I had to do was this:
Dim puzzleFactory As ChannelFactory(Of IPuzzleServer) = New ChannelFactory(Of IPuzzleServer)("PuzzleServer")
puzzleFactory.Endpoint.Address = New System.ServiceModel.EndpointAddress("net.tcp://" & frm.IP & ":3315/PuzzleServer")
Try
mPuzzleProxy = puzzleFactory.CreateChannel
mPlayerId = mPuzzleProxy.JoinGame(frm.PlayerName, frm.PlayerColor)
Catch ex As Exception
MessageBox.Show("Could not connect to host '" & frm.IP & "'. Reason: " & ex.Message)
Exit Sub
End Try
I hope that makes sense, if you have any questions feel free to email me.
Subscribe to:
Posts (Atom)