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