Tuesday, November 10, 2009

SQL Management Studio abomination

There is a burr in my side. Every day, I need to open SQL Management Studio 2008 for the same server. Problem is, the very first time I accessed this server, I did so using a different user name and password. Forever after henceforth, SQL Management Studio has refused to remove this old server entry from my dropdown list in the "Connect to Server" popup window.

Thanks to this incredible stupidity from Microsoft, I now get to click to change the user and enter a new password about 80 times per day--all because this premium, allegedly very smart sophisticated software has decided never to forget a former entry--even though I have deleted the Registered Server and recreated and so forth.

I have Googled in vain. I'm in despair and frankly angry about this nuisance, which wouldn't matter if I didn't have to open and close the tool so many times per day.

If anyone has any concrete suggestion on how I can defeat this thing, please let me know. I see from the internet that I am not the only one having this frustration, but I have yet to find any blog entry or suggestion to alleviate the problem.

Monday, September 28, 2009

Delete a maintenance plan after changing SQL Server 2008 name


I've seen a few posts on how to delete an older maintenance plan after you've changed the computer name for a default installation of SQL Server 2008, but none of the posts fully solved the problem. Below is what I had to do--with the caveat that you have to find your own id's:


USE msdb

DELETE
FROM dbo.sysmaintplan_log
WHERE subplan_id = '36F8247F-6A1E-427A-AB7D-2F6D972E32C1'

DELETE
FROM dbo.sysmaintplan_subplans
WHERE subplan_id = '36F8247F-6A1E-427A-AB7D-2F6D972E32C1'

DELETE
FROM dbo.sysjobs
WHERE job_id = '3757937A-02DB-47A6-90DA-A64AE84D6E98'

DELETE
FROM dbo.sysmaintplan_plans
WHERE id = 'C7C6EFAA-DA4D-4097-9F9F-FC3A7C0AF2DB'


Sunday, May 03, 2009

C# code to get schema of an Access table

I just wanted to dump the schema of a table in Microsoft Access. There is a lot of code on the web which purports to do this, but most of it didn't actually work, and most of it was not in C# (my current preferred language). So I am posting this here for anyone that needs it. Just change the path to the database file in the first line of code, and the name of the table ("taxa" in my example) in the second line of code. This program dumps the table schema to a file created by the LogFile object (also attached below) located in the application folder. You'll need to add "using System.Data.OleDb;" to the top of the file. Or, just download the code here. The code:



OleDbConnection conn =
new OleDbConnection(
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
"C:\\phycoaide\\phycoaide.mdb;Persist Security Info=False;");

// retrieving schema for a single table
OleDbCommand cmd = new OleDbCommand("taxa", conn);
cmd.CommandType = CommandType.TableDirect;
conn.Open();
OleDbDataReader reader =
cmd.ExecuteReader(CommandBehavior.SchemaOnly);
DataTable schemaTable = reader.GetSchemaTable();
reader.Close();
conn.Close();

LogFile.WriteLine(" ");
foreach (DataRow r in schemaTable.Rows)
{
LogFile.WriteLine(" ");
foreach (DataColumn c in schemaTable.Columns)
{
LogFile.WriteLine(c.ColumnName + ": " + r[c.ColumnName]);
}
}
MessageBox.Show("done");



The LogFile class creates a file in the application folder from which your program runs:



//
// No copyright; free for reuse by anyone
//

// Pat G. Palmer
// ppalmer AT harbormist.com
// 2009-05-04
// Opens a single-threaded log file to trace execution
namespace Ansp
{
using System;
using System.IO; // file readers and writers
using System.Windows.Forms; // Application object

///
/// Singleton that appends log entries to a text file
/// in the application folder. If the file grows
/// to be too large, it deletes itself and starts over.
/// The file is kept open until the application ends
/// and implements the "dispose" pattern in case things
/// do not end gracefully.
///

public class LogFile : IDisposable
{
private static int maxsize = 470000;
private static string fileSuffix = "_log.txt";
private static string fileSpecification;
private static StreamWriter filewriter;
private static LogFile instance;

private LogFile()
{
}

~LogFile()
{
this.Dispose(false);
}

public static void InitLogFile()
{
if (instance == null)
{
instance = new LogFile();
}

string stringMe = "InitLogFile: ";
try
{
if (Application.ProductName.Length == 0)
{
fileSpecification = Application.StartupPath + "\\" +
"Test" + fileSuffix;
}
else
{
fileSpecification = Application.StartupPath + "\\" +
Application.ProductName + fileSuffix;
}

// restart file if too big
if (File.Exists(fileSpecification))
{
FileInfo myFileInfo = new FileInfo(fileSpecification);
if (myFileInfo.Length > maxsize)
{
File.Delete(fileSpecification);
}

myFileInfo = null;
}

// restart file with appending
filewriter = new StreamWriter(
fileSpecification, true, System.Text.Encoding.UTF8);

// start log with standard info
WriteLine("\r\n---------------------------------------------");
string tempString = stringMe +
Application.ProductName + " " +
Application.ProductVersion +
"log opened at " +
DateTime.Now;
WriteLine(tempString);
WriteLine(stringMe + "username=" + SystemInformation.UserName);
WriteLine(stringMe + Application.StartupPath);
}
catch
{
}
}

public static void WriteLine(string myInputLine)
{
try
{
if (instance == null)
{
InitLogFile(); // first time only
}
if (myInputLine.Length != 0)
{
filewriter.WriteLine(myInputLine);
filewriter.Flush(); // update file
}
}
catch
{
}
}

public static void Close()
{
instance.Dispose();
}

///
/// Implement IDisposable.
/// Do not make this method virtual.
/// A derived class must not override this method.
///

public void Dispose()
{
this.Dispose(true);
//// Now, we call GC.SupressFinalize to take this object
//// off the finalization queue and prevent finalization
//// code for this object from executing a second time.
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (disposing)
{
// no managed resources to clean up
}
if (instance != null)
{
if (filewriter != null)
{
try
{
filewriter.Flush();
filewriter.Close();
}
catch
{
}

filewriter = null;
} // end if filewriter not null
} // end if instance not null
}

} // end class LogFile()
} // end namespace


Sunday, June 01, 2008

using Ruby, Tk and Eclipse

It took me a long time to learn howto do this. I found that on Windows XP, I had to use exactly these versions and install them in this order (rebooting in between):

* Ruby one-click installer v 1.8.6
* ActiveState Tcl v 8.4.x (NOTE: 8.6 did NOT WORK)

After this, the machine path was set to find both programs, AND I was able to configure Eclipse to compile using this version of Ruby, so I can now use Eclipse as the IDE. The trick is, when in the Ruby perspective, first create a Ruby project, and at that point, Eclipse gives you a chance to select a different Ruby virtual machine. Make sure then that you choose the Ruby.exe file installed by the Ruby one-click installer.

Sunday, May 11, 2008

Ruby and Tk on Windows may as well be a fantasy

Has anyone every actually tried to use tk to build a GUI with Ruby on
Windows
? Yes, Ruby runs on Windows. Yes, Tk runs on Windows. But the two do not communicate. Online instructions for binding Tk and Ruby are primarily for Linux, and ominously, use of Tk seems to require that one build one's own Ruby source from scratch in order to link Ruby with Tk.

If so, that is very discouraging and I probably won't consider it
worth doing. Furthermore, I would say it is false advertising the way
so many web sites glibly claim "and it runs on Windows too".

There are numerous discussion threads on the web where people have
sought help with this tk-Ruby linkage problem. These discussions threads seem to degrade shortly into hostility or contempt from Linux zealots towards the asking party, who continues to claim "but it doesn't work". I did finally find one posting claiming to achieve a solution. That method would require installation of multiple build tools including a C++ compiler! Not only would it take me at least two days to make it work, but also there is little hope of getting lab administrators where I am teaching to install something that burdensome.

Please tell me that Tk and Ruby on Windows is not an over-inflated pipe-dream. I hope to hear otherwise, but until I do so, Ruby--and more importantly, the much touted supportive Ruby community--has fallen somewhat in my estimation.