Jim Rogers

Lives in Baton Rouge, LA, with two dogs, one cat, and one lovely wife. I'm a lead developer for GCR & Associates.

Katrin and Jim

Month List

Removing a #region with Resharper

by Jim Sep 22, 2011 8:28 PM

Collasped

I hate opening up a source file and seeing that. No, not the VB.NET, though I’m not a fan of that either. I mean the fifteen region directives in a 312 line file. Most of those have one method in them. I guess at some point that was a coding standard or something - but dude, you’re making the code harder to read, not easier.

Neither Visual Studio nor resharper has a direct means of quickly removing individual region directives, though resharper can be configured to remove all of them when you reformat the file.

To remove specific regions, follow these steps:

Type Ctrl+Alt+F to display resharper’s File Structure window, shown below. The gray outlines correspond to regions.

Click the ‘x’ in the upper right corner of the region box. The start and end region directives will be removed, but the code they contain will remain.

image

An obscure DB2 error

by Jim Aug 17, 2011 9:06 AM

SQL1159 Initialization error with DB2 .NET Data Provider, reason code 7, tokens 9.5.0.DEF.2, SOFTWARE\IBM\DB2\InstalledCopies

For me the solution to this error was simply this: run my .NET website under IIS, rather than under Visual Studio’s development server. There are apparently other sources of this error, maybe related to x86 vs. x64 installations; IBM has some documentation of the error types.

If I had to guess, I would think that the IBM driver DLLs are trying to read from the registry, and the development server doesn’t have the necessary permissions. Reason code 7 is a registry error, and the tokens are an existing registry value and path under HKEY_LOCAL_MACHINE.

Tags:

Code

Sending email from a brinkster account in C#

by Jim May 20, 2011 1:52 PM

The examples on Brinkster’s support pages are hit and miss, and they’re in VB.

static void SendMessage(string email, string messageBody) {     var from = "you@yourdomain.com";     var credentials = new NetworkCredential(from, "password");     var message = new MailMessage()         {             From = new MailAddress(from),             Subject = "Subject",             Body = messageBody,             IsBodyHtml = true         };   message.To.Add(email);   var mailClient = new SmtpClient("mymail.brinkster.com", 2525)         {             DeliveryMethod = SmtpDeliveryMethod.Network,             UseDefaultCredentials = false,             Credentials = credentials         };     mailClient.Send(message); }

Things to note:

  • The from address must be the same email used to authenticate.
  • Port 25 is the standard, but if this doesn’t work (it didn’t for me,) try port 2525.

Speaking on Azure

by jim Mar 28, 2011 11:00 AM

I’ll be speaking at the upcoming Baton Rouge .NET User Group (BRDNUG) meeting on April 13th. The topic: An Introduction to Windows Azure.

More information is available at brdnug.org. (That link will likely be broken soon – try the base site at brdnug.org.)

My employer Antares Technology Solutions is sponsoring the event. Drop by if you’re in the area!!

Tags:

Code

Running NHibernate queries in management studio

by Jim Mar 17, 2011 5:33 PM
If you watch your NHibernate-generated queries go by in SQL Profiler, you’ll see a whole lot of SQL that looks like this:
declare @p1 int
set @p1=11
exec sp_prepexec @p1 output,N'@p0 varchar(8000),@p1 ...
SELECT TOP (@p1) this_.ProjectId as ProjectId78_0_, ...
',@p0='jimrogers',@p1=10,@p2='jimrogers',@p4=10
select @p1
But if you try to paste that into SQL Management Studio and run it, you get this error:
Msg 8179, Level 16, State 2, Procedure sp_prepexec, Line 1
Could not find prepared statement with handle 11.
Getting the query to run is simple enough – just comment out or delete the second line:
declare @p1 int
--set @p1=11
exec sp_prepexec @p1 output,N'@p0 varchar(8000),@p1 ...
SELECT TOP (@p1) this_.ProjectId as ProjectId78_0_, ...
',@p0='jimrogers',@p1=10,@p2='jimrogers',@p4=10
select @p1