|
Access and MSSQL
While working in Microsoft Access and Microsoft SQL Server, I needed a few things to make my work day a little easier.
Access Module: List ConnectionsI was trying to set up a proper DSN to a FoxPro table and was having a difficult time about it. If you can not find any help at ConnectionStrings.com, which would be rare, then this module will help you out. First, make a connection to the desired target in an Access database (not a project). Then, make a new module with this code in it.
Move your cursor to be in the function and hit the play button. All of the connection strings that are in your database will be shown in the debug window. Access Module: Strip Everything Except NumbersThere were some fields that contained both numbers and letters, but all I wanted were the numbers. I created a module and added this function to it.
Now, you can use StripValues() in your SQL statements, as in select id, StripValues(itemcode) from items SQL: CPU UsageOne day, our SQL server was acting up. We needed to see what was going on and what was chewing up all of the time. The below code will get a snapshot of what was going on, wait 10 seconds, then compare the current activitity to what was happening in order to determine how much CPU time was spent for the various tasks.
This code will not work well if the server is being chewed away by lots of little processes that get done in under 10 seconds. It is only good for those long queries that build massive tables and manipulate data for extended periods of time. SQL: Find TableThis slightly longer snippet will iterate through all of the databases in the system and will look for a database name that contains "asdf" – change that part in the code below. The code was written because we had access to a large system with thousands of tables in the various different databases, and we were looking for a table. We didn't know the full name, so that made our search even more difficult.
You might need special permissions on the server in order for this code to work, but then again, if you need this code to work, you should probably already have the permissions. SQL: Shrink All DatabasesIf your SQL server is running out of space and you need to delete some files to just get some more available hard drive real estate, you might run through all of the databases on your SQL server and shrink them and truncate the logs. This code does that for you on all databases.
With this script, you need the person to have appropriate privilages in order to perform the log truncation and the database shrinking, but you can get huge amounts of hard drive space reclaimed for the file system. | |||||