Thursday, July 26, 2007

The Case of the Missing Generic (Parse Method)

that was really helpful ot use Generics for Enum.Parse() :-)


Tuesday, July 24, 2007

How To: Shrink Sql Server 2005 Log Files

Shrink Sql Server 2005 Log Files

use YourDbName
backup log YourDbName with truncate_only

if you copy your databases, names are not always the same! based on how do you copy it it still has the same name like the source database.. keep attention when you run it - then it shrinks e.g. 130 GB -> 22 MB .... many information goes away.



today i done some researches and I found the following thread:

after some analyzing and test runs the follwoing solution worked for me:

DBName nvarchar(128),
DBLogicalName nvarchar(128)
SELECT DBName, DBLogicalName
FROM sys.databases db join sys.master_files mf
on db.database_id = mf.database_id
WHERE not in ('master', 'tempdb', 'model', 'msdb',
'distribution') AND type_desc LIKE 'log'

DECLARE @VarDBLogicalName nvarchar(128)
DECLARE @VarDBName nvarchar(128)
DECLARE @VarRowCount int

SELECT top 1 @VarDBName = DBName, @VarDBLogicalName = DBLogicalName
FROM #TDatabases
SET @VarRowCount = @@rowcount
WHILE @VarRowCount <> 0
EXEC(' use ' + @VarDBName + ' backup log '+ @VarDBName + ' with no_log
dbcc shrinkfile(''' + @VarDBLogicalName + ''', TRUNCATEONLY) WITH
FROM #TDatabases
WHERE DBName = @VarDBName
SELECT top 1 @VarDBName = DBName, @VarDBLogicalName =
FROM #TDatabases
SET @VarRowCount = @@ROWCOUNT
DROP TABLE #TDatabases

(otherwise search at google for: "osql shrink all db" in it doesn't fit your needs)

the above script you put now simply into a *.sql file (e.g.: shrinkalldatabases.sql).

now you need to create a second, which is simply a batch file (e.g.:startshrink.cmd) : *.bat or *.cmd. Into this file you write the following command:

osql -E -i shrinkalldatabases.sql -o result.txt

more info about osql you can find here:

all needed parameters are the following:

-E -> authentication
-i -> input file
-o -> output file

once you add it now to run once a week you have no further problems with your sql db sizes :-)

to have a small history and some additional information, here how I have created my *.cmd file:

@echo start: %date% %time% >> result.log
osql -E -i shrinkalldatabases.sql >> result.log
@echo end: %date% %time% >> result.log

enjoy it.

Sunday, July 22, 2007

Add/Remove Programs list are missing Change and Remove buttons

in resolution which i found at the following link, not all my programms appeard:

so i had to download : and then i could finally remove all my programs.

update: founded also a nice tool which shows exactly what kind of software you have installed: (you can do a lot, in case of very big AD's it's maybe not the right choice 5500++ Clients..)

Saturday, July 21, 2007

Windows Forms: "Cannot access a disposed object"

Well, good question what to do ... within forms i'm using normally a regular singleton factory after I received the following exception: "Cannot access a disposed object" I extended my code to the following:

#region Property: NetworkOverview
private NetworkOverview networkOverview ;

/// Gets/sets the NetworkOverview

public NetworkOverview NetworkOverview
get {
if (this.networkOverview == null)
this.networkOverview = new NetworkOverview();
if (this.networkOverview != null && this.networkOverview.IsDisposed)
this.networkOverview = null;
this.networkOverview = new NetworkOverview();

return this.networkOverview ;

Wednesday, July 11, 2007

How To: update within app.config file a key

today I had the pleasure to write a Setup for my project indeXus.Net Shared Cache (available on Codeplex). While others will install this WinService on various Hosts I needed a way how I can take the administration effort from the user.

In my case I had to update an appSettings Key within various *.config files and backup them into an Application Data Folder.

The solution seems to be very easy after I found all tricks....

15 static string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "");
16 static string appPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\MergeSystem\backup";

(thanks here to atif) some more coding between....

70 ///

71 /// Evaluates the and update machine IP within all Config files
72 ///

73 private static void EvaluateAndUpdateMachineIP()
74 {
75 IPHostEntry localMachineInfo = Dns.GetHostEntry(Dns.GetHostName());
76 DirectoryInfo dir = new DirectoryInfo(path);
77 foreach (FileInfo fi in dir.GetFiles("*.config"))
78 {
79 ExeConfigurationFileMap map = new ExeConfigurationFileMap();
80 map.ExeConfigFilename = fi.Name;
82 //Configuration config = ConfigurationManager.OpenExeConfiguration(fi.FullName);
83 Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
84 if(config.AppSettings != null && config.AppSettings.Settings != null)
85 {
86 if(config.AppSettings.Settings[WinServiceCommon.Constants.ConfigServiceCacheIpAddress] != null)
87 {
88 config.AppSettings.Settings[WinServiceCommon.Constants.ConfigServiceCacheIpAddress].Value = localMachineInfo.AddressList[0].ToString();
89 config.Save(ConfigurationSaveMode.Modified);
90 ConfigurationManager.RefreshSection("appSettings");
91 }
92 }
93 }
94 }

Monday, July 09, 2007

override ToString() with reflection

because i wanted to have a simple way to print my objects I adapted the following way to create my ToString() method within my objects:

(please not, do not use reflection within high performance environment)

#region Override Methods
/// <summary>
/// Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
/// </summary>
/// <returns>
/// A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
/// </returns>

public override string ToString()
StringBuilder sb = new StringBuilder();
#region Start Logging
Log.Debug("Entering method: " + ((object)MethodBase.GetCurrentMethod()).ToString());
sb.Append("Entering method: " + ((object)MethodBase.GetCurrentMethod()).ToString() + Environment.NewLine);
#endregion Start Logging

#region Override ToString() default with reflection

Type t = this.GetType();
PropertyInfo[] pis = t.GetProperties();
for (int i = 0; i < pis.Length; i++)
PropertyInfo pi = (PropertyInfo)pis.GetValue(i);
"{0}: {1}",
pi.GetValue(this, new object[] { })
sb.AppendFormat("{0}: {1}" + Environment.NewLine, pi.Name, pi.GetValue(this, new object[] { }));
catch (Exception ex)
BEShared.Utility.Log.Error("Could not log property. Ex. Message: " + ex.Message);
#endregion Override ToString() default with reflection

return sb.ToString();

#endregion Override Methods

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: Its free and easy to use, we provide all sources at codeplex.

Facebook Badge