Share This!

Friday, May 5, 2017

How to Check for any Changes in Table Data.


I am having a problem where some sneak process is changing the wrong
data in my inventory table. I wanted to discover how and when this was
happening, so I created a copy of my inventory table (on my local
machine, like this:
Select * from [dbo].[Inventory] into [dbo].[InventoryBASELINE]
Now I can check for discrepancies, like this...
select * from [dbo].[InventoryBASELINE] IB where CHECKSUM(*) <>
isnull((select CHECKSUM(*) from [dbo].[Inventory] I where IB.ID=I.ID),0)
union all
select * from [dbo].[Inventory] I where CHECKSUM(*) <> isnull((select
CHECKSUM(*) from [dbo].[InventoryBASELINE] IB where IB.ID=I.ID),0)
order by ID

This will show me any rows that are different, missing, or added between
my baseline table and my current table.
If I only cared about a few columns, I could use CHECKSUM(Customer, Qty,
Style) any columns I care about in all 4 checksum functions.

Friday, March 31, 2017

The Annoying Things About Visual Studio

As I work with VS, day in and day out, there are certain things that just annoy and frustrate me.  I will share them so the zero people who read this blog might have a snicker.

In General

  1. If you have an older app, say one that uses .net Framework 4.5.1, and you try to edit it on a machine that has a newer version, you CAN'T.  There is no way to install an older version of the framework alongside the newer version so you don't have to check 800 user machines for a framework update.
  2. Intellisense just quits 3 or 4 times a day without reason or warning.
  3. Editing a function name from the default (something like button1OnClick) to a real name (like LoadData) causes the designer to barf horribly,
  4. In Entity Framework, there are many objects that are created, named, and maintained by the framework.  Now and then you'll see an error message that some object you NEVER CREATED, DON'T KNOW ABOUT, and CAN'T EDIT has failed.
  5. The error messages most often have nothing to do with the problem, are too cryptic, and have a link to generic (useless) answers on the msdn site.

Desktop Apps

  1. When you are debugging, and you pooch the password, you get a massive error message, something about not being able to load System.Sql.Dll.
  2. In datagridview, CellChanged fires off for every cell while you are loading the data initially - and even when the column headers are being drawn, not just as you'd expect, when the data is - you know - changed.
  3. Now and then a form will get changed by the IDE in such a way that it will not compile.  This can happen even if you have not opened or edited the form.

Web Sites

  1. in MVC, there is no solid linkage between things.  A dropdown on a page named Customers will automatically find a list named Customers if there is one in the ViewBag.  This means the code looks like there is no list associated with the dropdown, you just have to know that if anything fills this list, it is used automatically, just because it's named the same.
  2. In an asp.net build, sometimes you need to build/deploy the dll's and sometimes you can just copy up the .cs files, presumably the webserver compiles for you.  I have no idea when one is required and when the other is.
  3. Also, isn't having a compiler in your webserver really dangerous?
  4. There is a script that will create the necessary tables for login, but there is no easy way to figure out how to force it to use SQL server instead of the default Access mdf database.

...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Saturday, March 4, 2017

system.data.pdb not loaded

There are some helpful pages about this, but I find that just stopping and recompiling the app usually fixes this.
...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Friday, December 30, 2016

Making Transparent PNGs in C#

This bit of code shows how to make a PNG with transparency totally from scratch in code.  This code will save the image back as a file, but it could as easily be streamed back to a web request.  This is a complete console app, if you want to compile it, you'll need to add a reference to System.Drawing.



using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace TransparentPNGTests
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var bmp = new System.Drawing.Bitmap(100, 100, PixelFormat.Format32bppArgb))
            using (Graphics g = Graphics.FromImage(bmp))
            using (Font f = new Font("Univers", 14f, FontStyle.Regular, GraphicsUnit.Pixel))
            {
                //set up bitmap
                g.Clear(Color.Transparent);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                //draw text                
                Brush b = Brushes.Black;
                Rectangle textrect = new Rectangle(5, 5, 90, 90);  
                
                //using the rectangle instead of a point is a quick way to do word wrapping on the graphic
                g.DrawString("This is a bunch of text, for testing.", f, b, textrect);

                //save from the bitmap
                g.Flush(FlushIntention.Flush);   //this seems to be wise, but unnecessary.
                bmp.Save("bmpsave.png", ImageFormat.Png);                

                //save from the image - loses transparency
                //Image image = Image.FromHbitmap(bmp.GetHbitmap());
                //image.Save("image.png");
            }
        }
    }

}


Note that the last 2 lines:

Image image = Image.FromHbitmap(bmp.GetHbitmap());
image.Save("image.png");
Are the wrong way.   This is the way you'll find if you Google for "How do I save a Graphic object to a file or stream".  Somehow, the GetHbitmap function manages to mangle the formatting out of the image.
Here are the resulting images from this code.
Bitmap.Save()

Image Save()

Monday, December 19, 2016

The item $/... does not exist at the specified version, or you do not have permission to access it.

Created some new views, and most of them worked OK, except one.

The item $/... does not exist at the specified version, or you do not have permission to access it.

Somehow the Team Foundation Server (TFS) thought the file already existed, even though I was trying to add it to source control for the first time.

How to solve.

  1. Copy and paste the text of the file to notepad
  2. Delete the file in Solution Explorer (this causes a check-out of the .csproj file)
  3. Check-in (this adds the "delete" to TFS).
  4. Now, in Solution Explorer, add the view (empty, without model)
  5. Note that there is now a [+] icon by the view in Solution Explorer
  6. Paste in the text from Notepad
  7. Save
  8. Right click the project (not just the added file) and check in. There should be 2 files in the changeset, the view and the .csproj.



Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.