"We live in an exciting time. The Internet has become almost ubiquitous throughout much of the world, bringing with it freedom of information and an unprecedented power to all. My passion is seeing businesses leverage that power effectively and economically." - Dave Ranck

Author Archive

May
19

Find a String Between 2 Strings

Posted by: Dave Ranck | Comments (0)

Here’s a way to return a substring of string that is between 2 strings in C#. There are other options for doing this, such as RegEx, but this is clean and simple.

// This search returns the substring between two strings, so 
// the first index is moved to the character just after the first string.
int first = str.IndexOf("$string1$") + "$string1$".Length;
int last = str.LastIndexOf("$string2$");
string str2 = str.Substring(first, last - first);
 
Technorati Tags: ,,,

Technorati Tags: C#, Code, Code Sample, Visual Studio

May
17

Restore SQL Database

Posted by: Dave Ranck | Comments (0)

Restoring a SQL Server database from a backup is easy to accomplish in the SQL Server IDE. Well, sometimes. In the real world, I often need to restore a development database, but the restore fails because I cannot gain exclusive access to the database. Some developers will detach the database and reattach it to grab exclusive access. If there are processes running frequently against the database, that may not work. Neither will killing all connections always work. The solution I’ve found is a short snippet of SQL to grab exclusive access, do the restore and then restore multi-user access. It looks like this:

USE master — Must be connected to a different database

-- Get exclusive access
ALTER DATABASE XXXXXX_Stage  SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

-- Restore from disk
-- Note WITH REPLACE http://msdn.microsoft.com/en-us/library/ms178615.aspx

RESTORE DATABASE XXXXXX_Stage  FROM DISK = 'F:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\XXXXXX_Stage _20100505.bak' WITH REPLACE

-- Restore multi user access
ALTER DATABASE XXXXXX_Stage SET MULTI_USER WITH ROLLBACK IMMEDIATE;

Note the WITH ROLLBACK clauses. You should take a production database down and make sure all transactions have completed. Then do a restore through the IDE. If you use the code above, you may lose some transactions or logs. This usually doesn’t matter in a test environment.

Have fun!

Technorati Tags: ,,,,,

Technorati Tags: Code, Code Sample, Database, SQL, SQL Server

I love code snippets. Way back in the early VB days, I created add-ins for the IDE that allowed me to create and save an array of short snippets of code and automatically insert them into the code window. I like to use snippets for things that I either don’t use often enough to remember, or to quickly enter templates for things I use a  lot to save time. Visual Studio .Net has a Snippet Manager and lets you create snippets in XML, but there is no built-in editor. There are a couple of editors available, some stand-alone and at least one called Snippet Designer that is integrated into the IDE. Read More→

Technorati Tags: Add-in, Code, Programming, Software Development, Tools, Visual Studio

Comments (0)
May
10

Create Singleton in C#

Posted by: Dave Ranck | Comments (0)

One of the most basic and most useful object patterns is the Singleton design pattern. A Singleton is a class of which there will only be one instance created at any time. All users of the Singleton class will all use the same instance. This is great for a wide range of applications such as cached values and lookups or utilities that execute quickly. The Design Patterns book by Gamma et al . describes the structure of a basic Singleton. We’ll describe how to create one in C#.

Read More→

Technorati Tags: Code, Design, Programming, Software Development, Tips, Visual Studio

May
05

Title Case in C#

Posted by: Dave Ranck | Comments (0)

Here a quick snippet to convert text to Title Case in C# that uses the TextInfo class. Note that strings with all caps will not be converted, so convert to lower case first.

// Defines the string with mixed casing.
string myString = "this iS a StrIng with MIXED CaSe";

// Create a TextInfo based on the "en-US" culture.
TextInfo tInfo = new CultureInfo("en-US", false).TextInfo;

// Changes a string to titlecase.
// Note the ToLower(), needed to convert words in all caps like MIXED
Console.WriteLine("\"{0}\" to titlecase: {1}", myString, tInfo.ToTitleCase(myString.ToLower()));

//Result: This Is A String With Mixed Case
Console.ReadLine();

// Defines the string with mixed casing.

string myString = “this iS a StrIng with MIXED CaSe”;

// Create a TextInfo based on the “en-US” culture.

TextInfo tInfo = new CultureInfo(“en-US”, false).TextInfo;

// Changes a string to titlecase.

// Note the ToLower(), needed to convert words in all caps like MIXED

Console.WriteLine(“\”{0}\” to titlecase: {1}”, myString, tInfo.ToTitleCase(myString.ToLower()));

//Result: This Is A String With Mixed Case

Console.ReadLine();

Mar
31

Eco-Friendly PC Disposal

Posted by: Dave Ranck | Comments (0)

What do you do with old PCs, cell phones and other e-devices? Staples has an eco-friendly disposal program. Dell products are free as are cell phones and some other devices. Other PCs, laptops cost about $10 US. They also destroy the data on the drives.

Be friendly to the planet when you dispose of old PCs!

http://www.staples.com/sbd/cre/marketing/ecoeasy/index2.html

 

What do you do with old PCs, cell phones and other e-devices? Staples has a eco-friendly disposal program. Dell products are free as are cell phones and some other devices. Other PCs, laptops cost about $10 US. They also destroy the data on the drives.

 

Be friendly to the planet when you dispose of old PCs!

Technorati Tags: Ecology, Help, Resources

Categories : Help and Info, Resources
Comments (0)
Mar
14

What is an open web?

Posted by: Dave Ranck | Comments (0)

The following challenge was on my Firefox homepage today:

Creating an open web is at the heart of the Mozilla project. And you’re a part of that. As one of thousands of people in the project, you have worked tirelessly to keep the Internet open, participatory and full of life.

The question is: why? Why do you participate? Why does the open web matter so much to you?

As we work to grow the Mozilla community, we want to explain what you’re feeling to everyone — your neighbours, your co-workers, your grandparents. We want them to understand the open web.

I just shared my definition of what an Open Web means to me. Why don’t you share yours?

http://mozilla.org/open
#mozopen

Click read more to see my response

Read More→

Technorati Tags: Business, Business and Technology, Internet, Software Development

Well, this was an interesting foray into Windows 7. I just purchased a new laptop and didn’t like the way the hard drive was partitioned. Why partition an NTFS drive at all? The manufacturer had created an 80 GB primary partition with a 420 GB extended partition. Of course the OS and user profiles are stored on the relatively small primary partition. This I did not like. I put a lot of music on my laptop, along with my development projects and multimedia files. 80 GB just won’t cut it. I could have purchased 3rd party software to repartition the drives (Win 7’s built in tool won’t do the job here) but I didn’t want to do that. The solution? Move the files to the d: drive and create a symbolic (hard) link to new location.

Read More→

Comments (2)
Feb
05

Good Azure Video from PDC09

Posted by: Dave Ranck | Comments (0)

Here’s a great intro to Azure from PDC 09. If you have not looked at Azure or Cloud computing in general, take a look at this video for an introduction. Cloud Computing is here and in use. It will only grow in the near future.

PDC Video on Cloud Computing with Azure

J9SYRP3G9ZUC

Technorati Tags: Architecture, Business, Business and Technology, Cost Benefit Analysis, Design, ROI, TCO

Here’s another ancient article I wrote that I recently reread. It is interesting to see what has changed since this was first published on SearchSOA almost 8 years ago (see link at end of article). There are also many things that have not changed in those years. Companies continue to be faced with the question of what technology platform to choose for their Line of Business (LOB) applications. Often decisions are made based on criteria that have not been properly matched to business objectives. Sometimes the result is that the new technology platform is abandoned in the not so distant future, with a corresponding loss of investment dollars.

With a Just Enough Technology approach, a company evaluates technology against its core problem or objectives. I work with business and technology leaders within a company to define their true objectives and then weigh the technology decisions with their business objectives as the main criteria. Read through this article on choosing between the Java and Microsoft platforms. Both technologies have evolved quite a bit since this was first published, but some of the core arguments remain to this day.

Read More→

Technorati Tags: Architecture, Business and Technology, Cost Benefit Analysis, Design, Programming, ROI, Software Development, TCO

Sponsored By :

 

 

Material in this site unless otherwise noted is Copyright David Ranck 2009, 2010