A few weeks ago I was debugging something and needed to take snapshots of a table every five seconds, as a quick solution a colleague started running the following SQL and I thought I’d share it for anyone else stuck in a pinch…
WHILE (1=1) BEGIN INSERT INTO tmp_snapshot SELECT field1,field2,field3 FROM table1 WHERE field4 = 'value' WAITFOR DELAY '000:00:05' END
Just change the time delay and the query and you’re off, of course you could be a lot cleverer with your WHILE conditions and rework this principle for loads of things. I thought it worth posting as many database folk forget the power of the humble while loop!
During a recent consolidation exercise I was migrating one database at a time and then taking the old copy offline, unfortunately one of the DBs had (un-knowingly) been my default database and next time I tried to log in I received the dreaded “Cannot open user default database. Login Failed.” message.
I tried one of the workarounds proffered by Microsoft for this exact problem only to receive exactly the same error message, thankfully I then came across this excellent post on SQL Server Nation which explains the entire issue from start to end and offers a couple of fixes based on your particular scenario.
In my case it was to execute the sp_defaultdb stored procedure using the OSQL utility, for example…
osql -Sservername -E -dmaster -Q”sp_defaultdb ‘username’,'master’”
Sincere thanks to Brandon Galderisi from SQL Server Nation for the fix.
There’s a great little feature of SQL Server that allows you to execute command-line statements, allowing you to run batch files, get directory listings or call executables. The feature is accessed via the xp_cmdshell Extended Stored Procedure, the syntax is pretty simple and looks like this…
EXEC sp_configure ‘show advanced options’, 1
– To update the currently configured value for advanced options.
– To enable the feature.
EXEC sp_configure ‘xp_cmdshell’, 1
– To update the currently configured value for this feature.
Recently I migrated a Business Objects XI Release 2 deployment to XI Release 3.1, a relatively straight-forward process but as always there are a few gremlins to avoid. Unfortunately the final playbook I used had too many sensitive details in it but during my trial-run I did make a few notes that served me well as a rough workflow and I thought it might be worth sharing.
It’s a mix of steps to take with a few hints thrown in, for the trial run I built a one-box solution (DB+BO on the same server) which isn’t necesarily good practice but works well as development box. Please bear in mind that this is by no means exhaustive and there’s no substitute for reading the Business Objects documentation…
- Create a domain user under which you Business Objects services will run.
- Install SQL Server 2008 R2 Express (you could use MySQL I but I prefer MSSQL).
- Ensure that SQL Server runs under the domain account (can be done during setup or afterwards).
- Create databases for the CMS + Audit DBs, create a user that you will use to authenticate with.
- Install any necessary ODBC drivers.
- Open Windows Firewall and allow inbound traffic on port 8080 (for Tomcat).
- Setup CMS + Audit ODBC Sources using c:\windows\sysWOW64\odbcad32.exe
(see: 32-Bit ODBC Drivers in Windows Server 2008 R2)
- Configure IIS to Enable 32-bit Applications + .NET Application Pool = Classic
- Install Business Objects (everything but MySQL).
- Open CCM, stop services and set SIA + Apache to run under domain account.
- Grant permissions on C:\Program Files (x86)\Business Objects to domain account.
- Restart services.
- Click “Update Objects” button in CCM (this solved an issue where some Authentication options were unavailable in the CMC).
- Log in CMC, configure AD Authentication - it’s best to follow the Windows AD SSO NTLM instructions in Business Objects Documentation.
- Run Import Wizard (I may post some tips later on but it’s quite straight-forward).
- On Windows 7 PCs go to Control Panel >> Java >> Advanced >> Security and tick “Enable Mixed Mode (run with protection)” – this solved an issue for WebI users.
- Set user input locale correctly (I’m in the UK and I had to do this on the client for each user).
I hope that helped, if you have any questions please leave a comment and I’ll see if I can expand on the above.
Aside from those integrated into SQL Server (e.g. xp_cmdshell) it’s not often I come across the need to use Extended Stored Procedures but an application I installed recently required that I add their custom procedure to the SQL Server housing the application data. Having been years since I had last added one it took a little figuring out since I would’ve expected to find it in Management Studio under “Server Objects” or “Management” but it’s somewhere entirely different.
To add/register an Extended Stored Procedure you’ll need to right-click on…
Databases >> System Databases >> master >> Programability >> Extended Stored Procedures
…and select “New Extended Stored Procedure”.
Next you’ll have to provide a (this will be the name the procedure is called by) and the path to the DLL, you can browse to the the .dll file by clicking on the elipsis.
The next step is vital since at the moment the only people able to actually use the Extended Stored Procedure would by sysadmins. All you have to do to remedy that is click on “Permissions”, click “Search”, type “public” in the text box and click OK as follows…
All you have to do now is tick the “Execute” permission to allow the ‘public’ users of the database (effectively everybody) to be able to use the procedure.
The completed dialog box should look something like this…
Then click “OK” and all should be well.
Starting my third day at SQLBits with a hat-trick of talks on technologies I’m unfamiliar with was a bit of a head-bender but an enjoyable one nonetheless. The first talk I chose was a great overview of how to use completely free tools (SQL Server Express 2008 R2, among others) with completely free spacial data (Ordnance Survey’s Open Data) to create spatial reports in Reporting Services. Since it’s not an area I’m working in at the moment I didn’t get any major take-aways but I do have an understanding of what’s possible and how to go about it – if you’re in the same boat you should check out FWTools, Shape2SQL and Grid InQuest.
The second talk was Matt Whitfield‘s ‘CLR Demystified’ and not being a developer I’ll admit that much of it went over my head but I get the basic principles and most importantly I know what’s possible and where I might make use of CLR. The most interesting avenues for me are the ability to write custom aggregate functions and define custom data types – I was also impressed with the opportunity to increase performance in certain text processing / forward log parsing situations.
The next talk I attended was a gentle introduction to PowerShell and James Boother did a good job of showing where it might be useful for admin tasks, in particular the example of purging old backup/log files based on age lit my eyes up. There was also a demo of PowerShell authenticating with Twitter and posting tweets as admin alerts, alas the demo failed but that could well have been a timeout on the Uni’s WiFi network or just plain old demo-gremlins. I must say thou that I still can’t view PowerShell with some sense of disappointment because with all it’s flexibility and power it’s so damned wordy and many of the tasks it performs could be achieved with less code that a good old Bash script.
As with Friday I attended Quest‘s lunchtime session run by Kevin Kline, Ian Kick, Brent Ozar and Buck Woody – they’re some of the most experienced guys in the SQL community and when you get them together they’re funny as he’ll too so I was both entertained and informed in their myth-busting quiz.
My first afternoon talk was Gary Short’s session on NoSQL which predictably sparked a few polite but irate rebuttals from argumentative DBAs but the session itself was an excellent whistle-stop tour of the predominant NoSQL technologies and use cases. I was encouraged to hear from someone experienced in the field that nobody has quite put together all the pieces to hook up BI tools (that traditionally expect relational/dimensional models or OLAP sources) to the NoSQL back-ends, it’s a shame since I might need to do so pretty soon – I guess I’m going to have to get my hands dirty then!
The final talk was from Kevin Kline of Quest who covered SQL Injection, it was an informative talk that gave me pause for thought about a couple ‘best practices’ that I probably ought to harden a little. Kevin recommended a few tools that I’ll definitely be checking out at some point, notably:
- HP Scrawlr
- Source Code Analyser for SQL Injection
- Assessment and Planning Tool
- Discovery Wizard
And a few handy sites/articles:
Once more it was a great conference and the free day was every bit as good as the paid day, I can honestly say that I walked out of the event already looking forward to the next one.