[Release] Simple MsSql Handler

05/08/2011 00:15 Spirited42#1
I'm going back to MySql because I like it better. Here's the sql handler I was using that works with Sql Express (When you install Visual Studio):

Code:
namespace 数据库
{
    using System;
    using System.Data.SqlClient; 

    public static class Connection
    {
        public static string Database, DataSource;
        public static byte Timeout;
        public static string ConnectionString
        {
            get
            {
                return @"Data Source=" + DataSource + ";"
                    + "AttachDbFilename=" + Database + @"\Project Resistance\Binaries\Database.mdf;"
                    + "Integrated Security=True;Connect Timeout=" + Timeout + ";User Instance=True";
            }
        }
        public static void Test()
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                try { conn.Open(); conn.Close(); }
                catch { Console.ForegroundColor = ConsoleColor.Red; 
                    Console.WriteLine("Database Problems Detected!"); 
                    Console.ResetColor(); Console.ReadLine(); 
                }
            }
        }
    }
}
Code:
namespace 数据库
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class SqlReader : IDisposable
    {
        public SqlDataReader DataReader = null;
        private SqlConnection conn = new SqlConnection(Connection.ConnectionString);
        public SqlReader(string command)
        {
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(command, conn);
                DataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch (Exception e) { Console.WriteLine(e); if (conn.State != System.Data.ConnectionState.Closed) conn.Close(); }
        }
        public void Dispose()
        {
            if (conn.State != ConnectionState.Closed)
                conn.Close();
            conn.Dispose();
            DataReader = null;
            conn = null;
        }
    }
}
Code:
namespace 数据库
{
    using System;
    using System.Data.SqlClient;

    public class SqlCmd
    {
        public SqlCmd(string command)
        {
            using (var conn = new SqlConnection(Connection.ConnectionString))
            {
                try
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand(command, conn);
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    conn.Close();
                }
                catch (Exception e) { Console.WriteLine(e); if (conn.State != System.Data.ConnectionState.Closed) conn.Close(); }
                conn.Dispose();
            }
        }
    }
}
Inside my configuration file:
Code:
[Database]
DataSource = .\SQLEXPRESS
Timeout = 30
Helpful Links:
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
05/08/2011 07:10 .Ryu#2
Can you not delete this one this time <_<
05/08/2011 07:16 Spirited42#3
Quote:
Originally Posted by .Ryu View Post
Can you not delete this one this time <_<
I don't plan to delete it but I wish you would delete that comment and stop posting it every time I release something.
05/09/2011 00:12 xScott#4
thats an odd namespace name (:
anyway, nice release fang.
05/09/2011 01:16 KraHen#5
It`s a really easy "wrapper"(?) to implement, IMO everyone developing a server should be able to figure something this straightforward out on their own.

I appreciate that you want to help, but IMO this isn`t the way to go for it. Just my opinion though.
05/09/2011 06:17 Spirited42#6
Quote:
Originally Posted by KraHen View Post
It`s a really easy "wrapper"(?) to implement, IMO everyone developing a server should be able to figure something this straightforward out on their own.

I appreciate that you want to help, but IMO this isn`t the way to go for it. Just my opinion though.
Well, it took me a good few hours to figure out, but then again... my laptop was having serious issues with Sql RC2.
05/09/2011 17:49 pintser#7

+1
Dummies:

to the creator:
伟大的工作,先生!
05/10/2011 01:11 .Kinshi#8
Quote:
Originally Posted by pintser View Post
+1
Dummies:

to the creator:
伟大的工作,先生!
哦 我的上帝,我可以使用谷歌翻译的!
05/10/2011 01:16 pintser#9
上午我好,还是什么?
---btw---
你是假的!
----------
xd
05/10/2011 02:42 Spirited42#10
其实...我没用Google译者
Translation: Actually, I didn't use Google Translator.
Try typing that sentence in and see if you get what I typed in Chinese. =]

Oh, 和感谢你
05/10/2011 08:06 Yoshimitsu™#11
我喜欢在后院下雨时雨水冰雹岩浆。
05/10/2011 09:19 Spirited42#12
Quote:
Originally Posted by Yoshimitsu™ View Post
我喜欢在后院下雨时雨水冰雹岩浆。
._. that was a messed up sentence.
K, no more Chinese. lol
05/10/2011 14:12 Korvacs#13
Ok enough of the chinese, everytime you write it you break a very simple rule >_>".

Not sure what the idea behind using Chinese was but i cant imagine its very useful when it comes to actually writing code, since you have to use it everytime you use that namespace..