Visual Studio* provides an application settings (aka properties) feature for console, library or windows applications. Creating and editing application settings at design time is straight-forward and can be managed conveniently thru VS's GUI.
But what if you need to change the settings at run-time? The answer is anything but obvious. The settings are contained in a class called "Settings," which derives from System.Configuration.ApplicationSettingsBase. You could of course rewrite the code in the settings class, but then if you decide to make a change in VS's GUI all of your handiwork is immediately hosed.
There's one adjustment you can make directly in the GUI that puts you a step closer to your goal. At the top of the Settings Designer screen, is a drop down box titled "Accessor Modifier." There are two choices: the default is "Internal." The other choice is "Public." Choose "Public." As we'll see, this one alteration allows us to change the value of the properties in our code.
The application expects there to be a static property called Default, of type Settings, in the class Settings. Default, the only instance of Settings that will be acknowledged by the app, is created for you automatically by VS. Default is essentially functioning as a singleton. Finally, ApplicationSettingsBase provides an indexer allowing us to reference the individual settings on Default.
Here's an example:
MyApp.Properties.Settings.Default["MyProperty"] = value;
Friday, July 23, 2010
Tuesday, January 26, 2010
ORA-12154 TNS:could not resolve the connect identifier specified
Hey Oracle enthusiasts. Here's a fun one. I encounter this just about whenever I try to configure, unsuccessfully, TNSNames.ora for ODP.NET. Recently, I decided stopped worrying about TNS and put everything into the connection string, like so:
Data Source=(DESCRIPTION= (ADDRESS_LIST=(ADDRESS=( PROTOCOL=TCP)(HOST=LOCALHOST)( PORT=1521))) (CONNECT_DATA=(SERVER= DEDICATED)(SERVICE_NAME = orcl))); USER ID=whatever;PASSWORD=********; "
This works every time.
It just seems as though TNS isn't worth the trouble.
Data Source=(DESCRIPTION= (ADDRESS_LIST=(ADDRESS=(
This works every time.
It just seems as though TNS isn't worth the trouble.
Wednesday, December 16, 2009
Backing Up Oracle, Easily
As a developer I have a need to replicate environments. As I now work regularly with Oracle, my environment-maintenance duties should include duplicating Oracle databases across various machines. But how in the world do you do that?
It's been a real eye-opener to research what's involved with Oracle administration. I've come to the conclusion that the Oracle company doesn't really bother itself with things like quickstarts. Sadly, all their documentation is written in documentation-ese. What a struggle.
A few days ago I broke down and tackled the Oracle restoration challenge. I finally restored my first Oracle database today, and I thought I'd document how to do it, for the benefit of others. Essentially, I copied files over from the old server to the new one. FYI, this is what as known as a "cold" backup and recovery because the databases are shutdown when the activity occurs.
1. First, run these commands in sqlplus or Sql Developer to find out which files need to be copied:
select name from v$datafile; -- this provides the datafiles
select name from v$controlfile; --this provides the control files
2. Note the redo files. They are in the same directory as the datafiles.
3. Now log into the database to be replicated as sysdba
$>sqlplus "/ as sysdba"
4. And issue the "shutdown abort" command
5. Similarly on the new server, issue the "shutdown abort" command
5. Copy all the files referred to in items 1, 2, and 3 above from the server to be replicated to the corresponding locations on the new server
6. Back in sqlplus on the server to be replicated, issue the "restart" command
7. Do the same for the new server
Congratulations! You should be up and running on the new server by now.
It's been a real eye-opener to research what's involved with Oracle administration. I've come to the conclusion that the Oracle company doesn't really bother itself with things like quickstarts. Sadly, all their documentation is written in documentation-ese. What a struggle.
A few days ago I broke down and tackled the Oracle restoration challenge. I finally restored my first Oracle database today, and I thought I'd document how to do it, for the benefit of others. Essentially, I copied files over from the old server to the new one. FYI, this is what as known as a "cold" backup and recovery because the databases are shutdown when the activity occurs.
1. First, run these commands in sqlplus or Sql Developer to find out which files need to be copied:
select name from v$datafile; -- this provides the datafiles
select name from v$controlfile; --this provides the control files
2. Note the redo files. They are in the same directory as the datafiles.
3. Now log into the database to be replicated as sysdba
$>sqlplus "/ as sysdba"
4. And issue the "shutdown abort" command
5. Similarly on the new server, issue the "shutdown abort" command
5. Copy all the files referred to in items 1, 2, and 3 above from the server to be replicated to the corresponding locations on the new server
6. Back in sqlplus on the server to be replicated, issue the "restart" command
7. Do the same for the new server
Congratulations! You should be up and running on the new server by now.
Wednesday, October 28, 2009
Google, My Friend
It's astonishing to me how well Google distinguishes itself in anticipating its customers' needs. I couldn't remember the file name for the Task Manager program. I only knew that it was some abbreviation of TaskManager.
I tried doing a search on "task manager command line" or something like that receiving nothing but frustration. But then remembering Google's "Did you mean . . .?" feature. I typed "cmd tskmngr" into Google's search box. There it was.
Did you mean: cmd taskmgr
Simple. Effortless.
I tried doing a search on "task manager command line" or something like that receiving nothing but frustration. But then remembering Google's "Did you mean . . .?" feature. I typed "cmd tskmngr" into Google's search box. There it was.
Did you mean: cmd taskmgr
Simple. Effortless.
How Again Do You Get Data Out of a Refcursor in Sql Developer?
There appears to be no way for me to memorize how to run a stored procedure in Sql Developer that uses a refcursor. So I'm putting an example here. That way I can refer to it any time I want.
variable CV_1 REFCURSOR;
declare V_INTUSERID number;
BEGIN
V_INTUSERID := 1;
spProc1(V_INTUSERID,:CV_1);
END;
PRINT CV_1;
variable CV_1 REFCURSOR;
declare V_INTUSERID number;
BEGIN
V_INTUSERID := 1;
spProc1(V_INTUSERID,:CV_1);
END;
PRINT CV_1;
Wednesday, October 7, 2009
Visual Studio Shortcut for Using Directives
My current vote for top Visual Studio shortcut goes to "Shift-Alt-F10." This little beauty will bring up the "Options to help bind the selected item" dialog which will allow you to command the UI to inject the appropriate "Using" directive at the top of a class. Trying to bring up this dialog with the mouse is tricky and time-consuming. Save those precious brain cells for something else.
"Add Reference" Dialog Delays
Today I decided to reduce the impact of an annoying problem with Visual Studio--the length of time it takes to initially bring up the "Add Reference" dialog. It can take a minute! I run into this delay constantly because I seem to almost always need to add a reference to System.Configuration to every project. My approach was to create a custom project template with the reference already included. Here are the steps I took:
The official documentation from Microsoft is here.
- Navigate to "C:\program files\microsoft visual studio 9.0\common7\IDE\ProjectTemplates\CSharp\Windows\1033"
- Copied the template ConsoleApplication.zip
- Navigate to My Documents\Visual Studio 2008\Templates\ProjectTemplates\Visual C#
- Pasted ConsoleApplication.zip
- Opened up the zip with "Open with > Compressed (zipped) folders" and dragged "consoleapplication.csproj" onto the desktop
- At line 45 added
- Saved the proj file
- Opened up the zip with Winzip (or use 7zip) and dragged in the new version of "consoleapplication.csproj"
- Closed winzip (or 7zip)
<Reference Include="System.Configuration" />
The official documentation from Microsoft is here.
Subscribe to:
Posts (Atom)
