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):
Inside my configuration file:
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...]
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();
}
}
}
}
Code:
[Database] DataSource = .\SQLEXPRESS Timeout = 30
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]