Click here to Skip to main content
15,888,803 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: zero int? Pin
CDP180222-Nov-11 2:52
CDP180222-Nov-11 2:52 
GeneralRe: zero int? PinPopular
harold aptroot22-Nov-11 2:57
harold aptroot22-Nov-11 2:57 
GeneralRe: zero int? Pin
Reiss22-Nov-11 5:20
professionalReiss22-Nov-11 5:20 
GeneralRe: zero int? Pin
harold aptroot22-Nov-11 0:36
harold aptroot22-Nov-11 0:36 
GeneralRe: zero int? Pin
BobJanova22-Nov-11 0:38
BobJanova22-Nov-11 0:38 
AnswerRe: zero int? Pin
Fabio Franco23-Nov-11 7:16
professionalFabio Franco23-Nov-11 7:16 
AnswerRe: zero int? Pin
KP Lee3-Dec-11 11:18
KP Lee3-Dec-11 11:18 
RantWhy SQL Server sucked on Friday Pin
Gary R. Wheeler20-Nov-11 5:45
Gary R. Wheeler20-Nov-11 5:45 
Our application uses SQL Server 2005 Express for a couple small data bases. I was adding logic to our migration app (moves the product from one machine to another) to backup the data bases. The simplest way to do this was to spawn SQLCMD to execute a backup command:
BACKUP DATABASE CPT TO DISK='C:\...\FILE.BAK'
It worked fine at the command line, producing a nice backup file I could then include in the migration data. Spawning SQLCMD from my migration tool was another story however. The command created the backup file, which my app would then get an 'access denied' error. The file exists in the path I specified, and is the right size. Right-click, Properties, select the Security tab, and I get a message that I'm not allowed to view the security properties of the file unless I take ownership of it.

What. The. F***.

As closely as I can tell, when SQLCMD is run from a command window, it tells the SQL service to create the backup file with administrator access. If SQLCMD is run from another process, the SQL service creates the backup file under the account it's running under, usually Network Service. In other words, it creates a file for you that you can't use.

After much cursing, Googling, a brief foray into the MSDN, and stifling the urge to e-mail a pocket nuke to Redmond, I discovered the solution. If you create the backup file yourself (with zero length), SQL Server will go ahead and 'append' to the existing file, leaving the file ownership and security settings alone. Adding two lines of code, a call to CreateFile() and one to CloseHandle() fixed the problem.

What pisses me off about this is that, since they clearly know how to set the file ownership properly when the command is run interactively, why not do it all the time? Isn't is harder to screw this up than it is to do it right? Mad | :mad:
Software Zen: delete this;

GeneralRe: Why SQL Server sucked on Friday Pin
OriginalGriff20-Nov-11 6:07
mveOriginalGriff20-Nov-11 6:07 
GeneralRe: Why SQL Server sucked on Friday Pin
Gary R. Wheeler20-Nov-11 7:35
Gary R. Wheeler20-Nov-11 7:35 
GeneralRe: Why SQL Server sucked on Friday Pin
sucram21-Nov-11 1:57
sucram21-Nov-11 1:57 
GeneralPerfect way to show a splash screen PinPopular
Vladimir Svyatski16-Nov-11 21:08
professionalVladimir Svyatski16-Nov-11 21:08 
GeneralRe: Perfect way to show a splash screen Pin
BobJanova17-Nov-11 0:20
BobJanova17-Nov-11 0:20 
GeneralRe: Perfect way to show a splash screen Pin
Chris Meech17-Nov-11 4:07
Chris Meech17-Nov-11 4:07 
GeneralRe: Perfect way to show a splash screen Pin
BillW3317-Nov-11 5:14
professionalBillW3317-Nov-11 5:14 
GeneralRe: Perfect way to show a splash screen Pin
Johann Gerell22-Nov-11 1:33
Johann Gerell22-Nov-11 1:33 
GeneralRe: Perfect way to show a splash screen Pin
RobCroll17-Nov-11 11:52
RobCroll17-Nov-11 11:52 
GeneralRe: Perfect way to show a splash screen Pin
Bernhard Hiller18-Nov-11 3:29
Bernhard Hiller18-Nov-11 3:29 
AnswerRe: Perfect way to show a splash screen PinPopular
Vladimir Svyatski20-Nov-11 2:51
professionalVladimir Svyatski20-Nov-11 2:51 
AnswerRe: Perfect way to show a splash screen Pin
Firo Atrum Ventus20-Nov-11 3:16
Firo Atrum Ventus20-Nov-11 3:16 
GeneralRe: Perfect way to show a splash screen Pin
Member 205300621-Nov-11 6:19
Member 205300621-Nov-11 6:19 
JokeRe: Perfect way to show a splash screen Pin
micmanos22-Nov-11 12:37
micmanos22-Nov-11 12:37 
GeneralDocument layout Pin
TorstenH.16-Nov-11 2:49
TorstenH.16-Nov-11 2:49 
GeneralRe: Document layout Pin
BillW3317-Nov-11 6:11
professionalBillW3317-Nov-11 6:11 
GeneralNot so much bad code as kludge Pin
Dalek Dave11-Nov-11 13:52
professionalDalek Dave11-Nov-11 13:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.