Monday, March 20, 2006

FOXPRO: Connection Pooling Sucks

Connection pooling can really suck when you're not using SQL server or another client/server based SQL. Take foxpro for example. Connection polling in OLEDB can keep a table "open" long after you've cleared references to it. This means that if you want the table exclusive later on you wont be able to because of the reference. I discovered this when I needed to physically delete a table that I had opened and read the information from



Dim strConnString = "Driver={Microsoft Visual Foxpro Driver};SourceType=DBF;SourceDB=C:\DBFDIRECTORY;Uid=;Pwd=;OLE DB Services=-4;"


The sample above shows that OLE DB Services=-4 will turn off that connection pooling on foxpro and close the table when you actually request it. There is some small performance hit here, but nothing to hollar about considering youre using foxpro anyhow. :)

Wednesday, March 15, 2006

VB.NET: SMTP Mail

Easy SMTP function in VB.NET


Imports System.Web.Mail.SmtpMail
Imports System.Data
Imports System.Data.SqlClient

Function SendEmail(ByVal strTo As String, ByVal strFrom As String, ByVal strBody As String, ByVal strSubject As String, Optional ByVal strCC As String = "") As Boolean
Dim email As New System.Web.Mail.MailMessage()
email.To = strTo
email.Cc = strCC
email.From = strFrom
email.Body = strBody
email.Subject = strSubject
email.BodyFormat = Web.Mail.MailFormat.Text
Try
System.Web.Mail.SmtpMail.SmtpServer = "primaryserver.com"
System.Web.Mail.SmtpMail.Send(email)
Catch e As Exception
Debug.WriteLine(e)
email.Body = strBody & vbCrLf & vbCrLf & "MAIN SMTP SERVER ERROR: " & vbCrLf & e.ToString
System.Web.Mail.SmtpMail.SmtpServer = "secondary server.com"
System.Web.Mail.SmtpMail.Send(email)
End Try
Return True
End Function

Tuesday, March 14, 2006

VB.NET: Strong Naming

Quick and ditry strong naming. Very helpful for no longer having to trust assemblys on a network.

Execute:

sn.exe -k PublicPrivateKeyFile.snk




'Strong Naming
<Assembly: System.Reflection.AssemblyDelaySign(False)>
<Assembly: System.Reflection.AssemblyKeyFile("mailpost.sn")>


One more note here, 1.0 looks in the current directory. 1.1 requires a full path to th key.

Monday, March 13, 2006

VB.NET: Formatting for bytes with commas

Formatting for bytes with commas. For example 1,000 or 1,000,000. While this is really basic, I almost always forget this.

include_once('/home/rwmech/public_html/robsprogrammingjunk/geshi/geshi.php');

$source = <<'To format a number with commas
Format(intBytesProc, "#,##0")

END;

$geshi = new GeSHi($source, 'vbnet');
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->set_overall_style('font-family: Courier New , Courier, Monospace; font-size: 8pt; word-wrap:break-word;');
$geshi->set_comments_style(1, 'color: #006600;');
$geshi->set_comments_style('MULTI', 'color: #006600;');
$geshi->set_header_content('Code Example © Robert Mech. May be used freely as long as credit is given to the source.');
$geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
$geshi->set_footer_content('If you use this code, please make a comment on the blog!');
$geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');

echo $geshi->parse_code();
?>