Monday, February 19, 2007

Restore mdf file without ldf in SQL Server 2005

We had some disk space issues on one of the drives and the reason was because one sql log file had 611 GB of disk space used, so I stopped the service and deleted the file hopeing that creating a similar database with the same name can generate an empty log file that I can use, but this was a mistake, so I searched around for a solution and most of the articles out there was kind of outdated, it mentiones solutions that are not supported anymore by sql server 2005, like changing system tables which is not supported anymore, so here is the solution:

--move the mdf file to a temporary directory, and create a new database with the same name, point it to use an existing mdf file


Create database on (FileName='W:\SQLServerData\temp\yourdatabasefilename.mdf')
for attach_rebuild_log

and this did the trick for me, the output was little weired:

File activation failure. The physical file name "W:\SQLServerData\myoldLogFile.ldf" may be incorrect.

New log file 'W:\SQLServerData\temp\newLogFile_log.LDF' was created.

And because you probably did this operation using a temporary location, you need to move the files, you can restart sql server service, detach the database, and move the files whereever you want, and then attach from the new location

it works!

Wednesday, January 17, 2007

Tip : SP1 solves Visual Studio 2005 Performance Issues!

I experienced some performance issues with visual studio 2005 yesterday, it started with taking long time to save a file, I thought that I have changed something, or added add-on that caused this to happen, also it took longer time to open the IDE, although I have a dual core with 3 G of memoory...

but thanks god, I downloaded sp1 from http://www.microsoft.com/downloads/details.aspx?familyid=BB4A75AB-E2D4-4C96-B39D-37BAF6B5B1DC&displaylang=en , it took some time to install but it the problem has gone immediatly !

Friday, January 12, 2007

Regex hangs with complicated expressions or long string inputs, the Solution

After some struggles and wondering why my application hangs sometimes without throwing any exceptions or errors in event log entries, I was able to find out that the Regex in .Net was the issue.
so I started investigating and there are some nice handy solutions online but it's little sophsiticated and coupled specifically with regular expressions, while if you use the ThreadPool class, it's much easier to control threads and start asynchronous processes and wait for it a for a certain amount of time until it either finishes or the time is up.

here is all what you need (vb.net 2.0 .net framework)!

Imports System.Threading
'you create a threadnotify object to monitor the asynchronous process
Dim ThreadNotify As AutoResetEvent = New AutoResetEvent(False)
'start the process
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf StartMyAsyncProcess), ThreadNotify)
'wait 1.5 seconds , if the time is over, the thread will halt itself and this program will resume.
ThreadNotify.WaitOne(1500, True)
end sub
'the asynch process
Private Sub StartMyAsyncProcess(ByVal state As Object)
in_string = Regex.Replace(in_string, "\s*\r\n\s*", vbNewLine)
state.set()
End Sub

Friday, November 17, 2006

Multiple Series Graphs
so far I have tried 2 technologies for adding graphs to my .net sites, I used the dotnetcharting component http://dotnetcharting.com/ and I also used the fusion flash component http://www.infosoftglobal.com/FusionCharts/ , they are both great, but when it comes to having multiple series, here comes the challenge !
the graphs XAxis points must be defined regardless of the different series added to the graph, in the first technology, the dotnetcharting component, it takes the first series data and it uses it as the base for the XSeries points. For the second technology, the fusion charts, it takes a XML element that defines the points on the XAxis.

It's very difficult if the values of XAxis among different serieses are not similar, and you have to add your own logic to handle it. so you start first by having a unique set of all points for the XAxis for all serieses, and then you order it. For example, lets assume that you have series1 and series 2,

series1 has the values for XAxis: Jan,Feb,March
series2 has the values for XAxis: March,Feb,April

so you will first need to define the unique elements: Jan,Feb,March,Apr. then you will need to order it. and also you might want to fill in the gaps for missing xaxis values, like in series2, it does not have the "Jan" values, so you will need to add it, and you will set it's value to 0.

It's not straight forward, but it's doable, hopefully I was able to make things more clear...