Free Ajax Updating Logo's

I just used this site, http://www.ajaxload.info/, a couple of times today for creating Ajax update animations for use with our YUI Update Panel. The site was pretty quick and much easier than me coming up with something myself.

Very Simple MySql Backup Script for Windows 2008

I just setup the following super simple backup script on our Six Day Development server. I know it needs more features. Perhaps the ability to rotate through the backup files. But shouldn't that be the job of my offsite backup job and not my local dump routine? Anyway, here its.

@echo off

:: Usage: CommandFilename [BackupType]

date /T
time /T
echo.

::
:: Set mysqldump parameters
::
Set mysqluser=root
Set mysqlpassword=xxxxxxxx
Set mysqlHost=localhost 
Set mysqlOptions=--opt

::
:: Set backup file location
::
Set backupDir=D:\Data\Backups\MySql\

Set baseFileName=%backupDir%mysqlbackup_%date:~10,4%%date:~4,2%%date:~7,2%

set backupFileName=%baseFileName%.sql
Set zipFileName=%baseFileName%.zip


:: -----------------------------------------------------------------------------
set mysqlcmd=mysqldump %mysqlOptions% --all-databases --user=%mysqluser% 
          --host=%mysqlHost% --result-file=%backupFileName%
echo.
echo Performing mysqldump of %mysqlhost%
echo Dump command: %mysqlcmd%
echo.

:: Execute the backup
%mysqlcmd% --password=%mysqlpassword%
if %ERRORLEVEL% NEQ 0 goto errors


::-----------------------------------------------------------------------------
:: Zip up the backup file using 7zip and remove the initial backup file

7z a -tzip %zipFileName% %backupFileName%
if %ERRORLEVEL% NEQ 0 goto errors

:: Delete the .sql file
del %backupFileName%
if %ERRORLEVEL% NEQ 0 goto errors

echo.
echo Backup complete!
echo.
goto finish


REM: How to use screen
:usage
echo.
echo Usage: Backup sript for MySql
echo.
goto done


REM: error handler
:errors
echo.
echo WARNING! Error(s) were detected!
echo --------------------------------
echo Please evaluate the situation and, if needed,
echo restart this command file. You may need to
echo supply command parameters when executing
echo this command file.
echo.
goto done


REM: finished execution
:finish
echo.
echo Script execution is complete!
:done
date /T
time /T
echo.

Google Apps for Domains ... does not like system account

We ran into an interesting error today trying to send email from our company web site using our Google Applications for Domains smtp server.  In short here was the code we were using to send email from our contact form:

public static void SendMail(string to, string subject, string body)
        {
            var m = new MailMessage()
            {
                Subject = subject,
                Body = body
            };
 
            m.To.Add(ConfigurationManager.AppSettings["ContactToAddress"]);
            
            var s = new SmtpClient();
            s.EnableSsl = true;
            s.Send(m);
        }

We had our Google SMTP settings setup in our web.config file as follows:

<add key="ContactToAddress" value="info@mydomain.com" />
.
.
.
<system.net>
  <mailSettings>  
    <smtp from="system@mydomain.com" deliveryMethod="Network">
      <network host="smtp.gmail.com" port="587" userName="system@mydomain.com" 
password
="######" defaultCredentials="false"/>
    </smtp>
  </mailSettings>
</system.net>

This should be a no-brainer. We've had our Google Apps account for several months and have had no issues. So we know our DNS settings are correct and up to date.  But once we deployed this code to our server we started receiving a fail messages from Google:

PERM_FAILURE: Message rejected.  
See http://mail.google.com/support/bin/answer.py?answer=69585 for more information.

 

All the mail messages would show up in the system mail account sent items folder but would then get rejected as spam before being sent to the info distribution list at the same domain.

But wait it gets weirder the same email message form within the Gmail interface would be sent just fine! 

 

It was clear that something was causing Gmail to reject a message sent from and too itself.  Eventually we changed the user who we were using to send the email from 'system' to 'webcontact' and the messages started being delivered successfully. Yet another reason to hate spammers for making my life harder than it needs to be.

Self Signed SSL Certificates in IIS7

Today I had my first "Aha!" moment with IIS7... well almost.

I've been using IIS7 locally on my Vista development machine for some time now but I must say I've been missing the familiarity I've gained with IIS6 over the last several years. Now before somebody starts telling me about all the great new features in IIS7, I love the way IIS7 allows more configuration in side my web.config files for ASP.Net and I'm ecstatic about how it supports the new ASP.Net MVC framework. It's just that I haven't had much time to really play with these new features.

Well, today I was working on a WCF application that I initially wrote on IIS 6. When I was running some local integration tests I was reminded that my services were configured to run over HTTPS. Oh well, I thought off to create yet another self-signed certificate for IIS but before I went off down my usual path I decided to do a quick Google search on "self signed ssl iis7". To my delight I pulled up a blog post by Scott Guthrie on this exact topic. Come to find out IIS7 came with a UI tool for creating self signed certificates in IIS. Yes, I thought, one less command line for me to remember. I quickly ran through the certificate wizard and added the certificate to my web site reran my integration test and BANG...everything exploded.

Come to find out the self signed certificate wizard in IIS 7 only registers the certificate a CN equal to the host name. So while the hostname I was using to access my site was local.onfile.com the certificate would only register as my computer name, alhanson.

Oh well, so much for this new feature, back to the trusty selfssl.exe tool from the IIS6 resource kit. Which looks to be working well for me now.

99Designs.com Logo Contest

I am in the process of starting up a new consulting and software company with my friend, and now business partner, Lance. We're both definitely not designers and when want to keep startup costs low so when it came time to create a new logo for our company we launched a design contest on 99Designs.com

We're really happy with the number and the quality of the designs we've seen so far. If you need some design work 'crowd sourced' you should check it out.

Also, check out our design contest and let us know what you think of the submissions.

Later!

ReSharper 4.0 Beta

Finally after much waiting ReSharper 4.0 has finally gone beta...wait a minute haven't those other guys already shipped a production .Net 3.5 compatible version. Oh well, I love ReSharper and I'm excited about the update.

Computer Garage Sale

My friend Brad Loyd is having a computer garage sale this Saturday.  If you're looking for some old hardware to much around with it should be worth checking out.

Read more about it from his craigslist post: http://boise.craigslist.org/gms/676881266.html

DbLinq: A Linq Provider for MySQL

In my last post I walked through an example of connecting to MySQL database from .Net. As I begin to build my actual application today I was reluctant to begin building some classical data model on top of ADO.Net. I was really missing Linq and that's when I stumbled up on DbLinq a Linq provider for MySQL (and several other databases: SQL Lite, Oracle, etc).

The very light documentation on the DbLinq web site listed three easy steps to get started so I figured I'd give it a try.

1. Download source code package, compile in Visual Studio.
2. edit and run script 'run_myMetal.bat' (or run_oraMetal or run_pgMetal) to generate a C# file representing your database
3. include DbLinq.Mysql.dll and the new file in your project (or DbLinq.Postgres.dll etc)

Downloading the Source Code

Downloading the source code was simple enough. I simply did an svn checkout from http://dblinq2007.googlecode.com/svn/trunk opened up the DbLinq.sln solution file and everything compiled successfully, which is always a good sign! So far so good on to the 'run_myMetal.bat' file.

 

run_myMetal.bat

The run_myMetal.bat was located in the DbMetal folder and was just a simple wrapper around the DbMetal.exe application. The contents of the file were pretty simple:

   1: REM: note that the '-sprocs' option is turned on
   2:  
   3: bin\DbMetal.exe -provider=MySql -database:Northwind -server:localhost -user:LinqUser -password:linq2 -namespace:nwind -code:Northwind.cs -sprocs

I updated the database parameters and once I typed in my password correctly the script generated a single .cs file for me to use in my application.  Now on to see how well it works in my own project.

Using the DbLinq Provider

The source code comes with an example project for calling Mysql in the Example\DbLinq.MySql.Example folder but I always learn better starting with my own project from scratch. So once again I created a new Console application in Visual Studio 2008. To get the project to compile I had to the following references to my project:

  • DbLinq
  • DbLinq.MySql
  • MySql.Data
  • System.Configuration
  • System.Data.Linq

I also add an app.config file to hold my connection string and I had to change the class declaration in my generated class to inherit from DbLinq.MySql.MySqlDataContext instead of DbLinq.Linq.DataContext. (Probably something to do with the way I called DbMetal.)

After making these changes I added the following code to the Main method in Program.cs:

   1: static void Main(string[] args)
   2:        {
   3:            String connStr = ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString;
   4:  
   5:            AutomallDataContext db = new AutomallDataContext(new MySqlConnection(connStr));
   6:  
   7:            var dealers = from d in db.Dealers
   8:                          select new Dealers() { Address = d.Address, Name = d.Name };
   9:  
  10:  
  11:            foreach (Dealers dealer in dealers)
  12:            {
  13:                Console.WriteLine("Dealer: {0}, {1}", dealer.Name, dealer.Address);
  14:            }
  15:  
  16:            Console.ReadLine();
  17:                          
  18:        }

 

and got the following results:

dblinq_results

 

I consider that a big success. Now I'm ready to actually go and create something useful.  Catch you next time.

Connecting to a MySql database from C#

At my current job we recently licensed and installed our first Apache and MySql based application. We are mostly a .Net shop.  So while I am happy to have an Apache and MySql application running because it's going to bring us in money I really didn't want to add an additional programming language to our development roadmap.  The unfortunate thing is that we have already been asked to create several nightly import processes for the MySql database.

Usually I would start with a more robust database abstraction layer using something like nHibernate but since these are some simply throw away scripts I figured I'd start by just connecting directly to the MySql database and perform the updates.
 

Installing the MySql .Net Connector

If you haven't already installed MySql you can download it here. We were using version 5.0.45. Just follow the instructions in the .msi to get the server installed.

Next I needed to download the MySql connectors for .Net.  You should also be able to use a standard ODBC connection to access the MySql database but I like to use a database specific adapter when there's on available. The install is pretty straight forward and actually includes the MySql GUI Tools so there is no need to download those installers separately.

mysql_connector_install1

MySql Install #1 - Select 'Custom' to see available install components

mysql_connector_install2

MySql Install #2 - Select available components

Creating a Sample Project

Using Visual Studio 2008 I created a sample console application named "MySqlSample". I quickly added an Application Configuration file and a MySqlUpdater class to the project.

mysql_projectstructure

When you install the MySQL Connector for .Net the installer adds the MySQLDatabase as a connection option from the Server Explorer->Add Connection Dialog. If you like to be able to browse your database from within Visual Studio this is a nice feature and is very easy to setup.

mysql_addconnection

Add new MySQL database Connection

mysql_connector_addconnection

Connection Properties

mysql_serverexplorer1

New Connection in Server Explorer

On to the Code...

Okay, so now that all my installs are out of the way and I know that my connections are working between my work station and my MySQL database server I can move on into the code.   First I added a new connection string element to my app.config file:

<connectionStrings> 
<add name="MySqlSample" connectionString="server=msdev01;database=am_centraloregon;user id=root;pwd=####"/>
</connectionStrings>

I then had to add a reference to the MySQL.Data library to my sample project.

mysql_addreference

 

I then went into the MySqlUpdater class and added the following code to create a connection and update a single row into the makes table and to return the id of the new row.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Configuration;
   4:  using System.Linq;
   5:  using System.Text;
   6:  using System.Data;
   7:   
   8:  using MySql.Data.MySqlClient;
   9:   
  10:   
  11:  namespace MySqlSample
  12:  {
  13:      public class MySqlUpdater
  14:      {
  15:   
  16:          public long AddMake(string name)
  17:          {
  18:              MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlSample"].ConnectionString);
  19:   
  20:              try
  21:              {
  22:                  conn.Open();
  23:   
  24:                  MySqlCommand cmd = new MySqlCommand();
  25:                  cmd.Connection = conn;
  26:                  cmd.CommandText = "Insert makes (Name) Values (@name)";
  27:                  cmd.CommandType = CommandType.Text;
  28:                  cmd.Parameters.Add("@name", name);
  29:   
  30:                  cmd.ExecuteNonQuery();
  31:   
  32:                  return (cmd.LastInsertedId); 
  33:              }
  34:              finally
  35:              {
  36:                  if (conn != null)
  37:                      conn.Close();
  38:              }
  39:   
  40:          }
  41:      }
  42:  }

Nothing super exciting here. Looks a lot like accessing a MS SQL 2005 database using System.Data.SqlClient. Obviously we're using the MySqlConnection and MySqlCommand classes but everything else is pretty standard.
 

Conclusion

Obviously this code is a very simplistic example but at least now I know that all my plumbing is working between Visual Studio and my MySQL installation.  No I'm ready to move up to a higher levels of abstraction.

Late to the Party: Deki Wiki and the Cloud


My favorite wiki engine is by far Deki Wiki from MindTouch . I don't know if I like it so much because of it's slick UI, easy to install VM Image or the fact that I can write custom extensions for it using .Net (under Mono). If you haven't check it out download their VM image or even fire up one of there free hosted instances at http://www.wiki.is and take it for a test drive.

Anway, today in the MindTouch blogs Steve Bjorg was commenting on how the Google Application engine is the missing piece of the Cloud software revolution and he talked about some of the possibilities that the Google Application Engine could open up for Deki Wiki and products like it. I've looked at Amazon S3 for attachment an media storage for several applications. In fact I'm working on a low cost podcasting engine for churches with Lance Fisher that will have the option to use Amazon S3 as the backend for media storage. But until today I had never thought of trying to run the entire application in the cloud.  Maybe I'm late to the party but I've always limited my view of the could to Google Applications and services like S3, or even Flickr.

But if MindTouch can successfully get a product with the quality and complexity of DekiWIki running in the cloud then I think we're all going to have to begin to rethink how we purpose and deploy our applications. 




«August»
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456