the internet in my apt.
Saturday, June 6, 2009
Friday, June 5, 2009
Looking for a job in germany....
Hello Planet, I am hoping you can help me!
I am currently looking for a new job. I have always wanted to live and work in Germany. I know people in Germany read the planet, so maybe, if anyone out there in Deutschland is looking for a .NET programmer/Systems Administrator/All around computer tech guy and is willing to sponsor a work visa, let me know in the comments or email me at bperry.volatile[at]gmail[dot]com and I will get you a resume.
I have managed Linux and Windows servers for the past three years, written .NET professionally for about one and a half years, and have excellent recommendations!
Thanks a bunch!
I am currently looking for a new job. I have always wanted to live and work in Germany. I know people in Germany read the planet, so maybe, if anyone out there in Deutschland is looking for a .NET programmer/Systems Administrator/All around computer tech guy and is willing to sponsor a work visa, let me know in the comments or email me at bperry.volatile[at]gmail[dot]com and I will get you a resume.
I have managed Linux and Windows servers for the past three years, written .NET professionally for about one and a half years, and have excellent recommendations!
Thanks a bunch!
Monday, June 1, 2009
Running SQL scripts in order from C# code
I have a folder of SQL scripts being compiled as embedded resources. They are named as such:
01 FirstTable.sql
02 SecondTable.sql
etc...
so that way I can run them in the order they need to be run in when say, resetting a database. The problem I ran into was getting the resources through reflection gave them to me in the wrong order... the second script was trying to be run first and it relies on the first script, so that obviously didn't work. Running Array.Sort() on the script list fixed this problem. The code ended up looking like:
This works great in mono. This was just a test method, so there is no real error checking, so be careful.
01 FirstTable.sql
02 SecondTable.sql
etc...
so that way I can run them in the order they need to be run in when say, resetting a database. The problem I ran into was getting the resources through reflection gave them to me in the wrong order... the second script was trying to be run first and it relies on the first script, so that obviously didn't work. Running Array.Sort() on the script list fixed this problem. The code ended up looking like:
public void Reset()
{
if (string.IsNullOrEmpty(ConnectionString) && Connection == null)
throw new Exception("Connection string and connection are null.");
else
{
if (Connection == null)
Connection = new MySqlConnection(ConnectionString);
Connection.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "DROP DATABASE SystemsLogica; CREATE DATABASE SystemsLogica; USE SystemsLogica;";
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = Connection;
cmd.ExecuteNonQuery();
Assembly asm = Assembly.GetExecutingAssembly();
string[] scripts = asm.GetManifestResourceNames();
Array.Sort(scripts);
foreach (string file in scripts)
{
Stream res = asm.GetManifestResourceStream(file);
byte[] resbytes = new byte[res.Length];
res.Read(resbytes, 0, (int)res.Length);
Console.WriteLine(file);
Console.WriteLine("-----------------");
Console.WriteLine(Encoding.ASCII.GetString(resbytes));
Console.Write("\n\n\n");
using (cmd = new MySqlCommand())
{
cmd.CommandText = Encoding.ASCII.GetString(resbytes);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = Connection;
cmd.ExecuteNonQuery();
}
}
Connection.Close();
}
}
This works great in mono. This was just a test method, so there is no real error checking, so be careful.
Subscribe to:
Posts (Atom)