Back with ASP.net 1.1, if you set a connection string in your Web.config file, you could set it with something like this:
<add key="ConnectionStringName" value="ConnectionStringData" />
and get access to the string in your code with something like this:
string connString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionStringName"];
With ASP.net 2.0, while you can still use appsettings if you so desire, there are now subsections allowed in the Web.config, one of which is set aside for database connection strings. Here is how to use it:
<add name="ConnectionStringName" connectionString="ConnectionStringDetails"/>
The good news with this is that the connection string within your Web.config file is no longer just some string (that while you may know it is a connection string, your application has no intrinsic knowledge of this). Your website can now access this string in a number of different ways, in general making your life easier (especially when using the Website Configuration screens, or any of the built-in data access controls).
All of this is old news. However, while the process for retrieving a connection string in 2.0 is well-documented when you are doing it from within the setup wizard of a DataAccess control, I had some trouble figuring out how to retrieve it solely within the code. Eventually (with some help from Google) I was able to find the exact syntax, and I am passing it on here so that it might help someone else facing the same problem.
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
When I started getting into more of a development role in my previous job, and was using Visual Studio, C# and ASP.net more and more, I was a frequest visitor on sites devoted to .Net programming like Code Project and 4Guys. One day on CP, I saw a review of an extension for Visual Studio 2003 called Visual Assist X. The review descibed how this product helped improve the native intellisense in VS, and in general added shortcuts and other things to make the program friendlier to use. They offered a 30 day trial, so I downloaded and installed.
Within a couple of days, I was hooked. I got my boss to approve it, and sent $130 to Whole Tomato Software in exchange for a license to use their program.
I did not notice how much I relied on its features to help me speed up my overall development time until I had to switch to a different computer recently (one without Visual Assist X installed). As I started to code in Visual Studio, I was waiting for the extremely helpful (and actually intelligent) intellisense that I was used to to pop up with suggestions as to what variable I was looking for. The program is so well-integrated into VS that I had forgotten that it was separate. Suffice to say, I right away went to the site and downloaded a copy of the most recent build (and extended support with them in the process). Now that it is installed, Visual Studio seems much more familiar again (and I have made my coding at least 30% faster).
Note: I have no affiliation with Whole Tomato, nor do I receive any kickbacks or referral fees. I am just writing to let you know about a product that will almost certainly make Visual Studio friendlier, improve your overall productivity in the IDE (and pay back the investment within a few days).
Technorati Tags: Visual-Studio, Visual-Assist-X, Whole-Tomato-Software, Extensions, IDE, C#, ASP.net, Development, Tools
Things I found interesting on April 5, 2006:
- Contract Changes – Keith Casey tells about some seemingly “draconian” additions he has made to his standard consulting contracts.
- C# Tivia Quiz Part 1 – From Eric Gunnerson, a list of (some serious, some not serious) questions about C# (via the Daily Grind)
- 01:02:03 04/05/06 – The way the clocks looked this morning, if you count days with mm/dd/yy. This was from the JOS Discussion group, but it looks like it was moderated out. (I got it from RSS)
- How I work: Bill Gates – Read about the tools that Bill uses in the office every day. (Wow, three monitors helps productivity? Who woulda thunk it?)
- Microsoft Says Recovery from Malware Becoming Impossible – “a Microsoft security official said businesses should consider investing in an automated process to wipe hard drives and reinstall operating systems as a practical way to recover from malware infestation.” Ouch.
- TIOBE Programming Community Index – See what programming languages are most popular (who would have thought that BASIC is more popular than C#) in this search-engine-based unscientific study
- Fire your Boss! The Successful Home Freelancer’s Guide – From Neil Flanagan and Jarvis Finger @ Sitepoint.
Technorati Tags: consulting, contracts, c#, bill-gates, malware, microsoft, languages, freelancing
Technorati Tags: software-development, asp.net, ATLAS, CSS, Visual-Studio-2005, textbox, SecureString, Webservice, Performance, feed-readers, c#, interview
First a disclaimer: I have never used Visual Studio 2005 (except for an early beta Express edition) nor have I used ASP.net 2.0 (I plan to start in the next couple of days). I have been doing lots of ASP.net programming and application development using the .Net Framework (1.14322), C#, VS 2003 and SQL Server 2000.
That said, I am getting personally excited (in a professional way) about the improved development potential with ASP.net 2.0
A few things that I have seen recently that have influenced my opinion enough to write the previous sentence:
- Scott Guthrie has posted an account of how MySpace is using ASP.netand how switching to the new platform (fresumably from ColdFusion) affected their performance:
- They are processiong 1.5 billion page views per day, reaching 2.3 concurrent users
- After switching to ASP.net 2.0, their server utilization went down from 85% to 27%!
So if you are considering the platform, you wont have to be concerned about any scaling or performance issues (assuming you know what you are doing). (I wonder how php would compare, with caching and everything else. Would it even be 50% as efficient as pre-compiled code? 30%?)
- The ATLAS framework has just received a go-live license with its March CTP release. ATLAS is Microsoft’s version of Ajax for ASP.net. It may not be ROR, but if you check out this demonstration video (worth watching for both the ATLAS demo as well as the demonstration of the new improvements to the product that make development go faster) I hope you will agree that it is definitely something worth trying out.
- For just a quick taste of other features touched by the upgrade (as well as totally new additions), check out some of the webcasts on the ASP.net Developer Center
They may not ship everything on time…but once they get their products out the door, they (often?!) can really shine.
So I created a Windows Service (based on this) that is designed for one purpose: to call a Web Service on my ASP.net application every 2 minutes that will perform certain jobs (like sending emails, other maintenance). In the config file for the service there is an appsetting labeled <add key=”Namespace.WebServiceName” value=”http://WebServiceAddress/JobRun.asmx”/>.
According to this article, by changing the key for this appsetting before installation of the Windows Service, the Windows Service would call the Web Service identified by the key. So it was written.
In the the Solution Manager in VS 2003, there is a Property under the Web Service called “URL Behavior”. This can be set either to “Static” or to “Dynamic” (see here for more official info).
- When set to Static, the URL that is entered for this Web Service when the Web Service is first referenced in VS is the url that will always be used.
- When set to Dynamic, the Web Service will always use the URL located in the config file | appsettings.
Obviously, in order for the Windows Service to function properly (ie: call the Web Service that is indicated in the Config file), the URL Behavior property of the Web Reference must be set to Static. Unfortunately for me, during my editing of this file and changing of the Web Reference, I forgot to set my Web Reference from its default behavior of Static to its correct behavior of Dynamic. Thus wasting many of my hours and killing many of my brain cells. Don’t let it happen to you.