|
You last visited: Today at 01:21
Advertisement
[Release] Simple MsSql Handler
Discussion on [Release] Simple MsSql Handler within the CO2 PServer Guides & Releases forum part of the CO2 Private Server category.
05/08/2011, 00:15
|
#1
|
elite*gold: 0
Join Date: Jan 2011
Posts: 470
Received Thanks: 97
|
[Release] Simple MsSql Handler
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:

|
|
|
05/08/2011, 07:10
|
#2
|
elite*gold: 0
Join Date: Dec 2009
Posts: 583
Received Thanks: 119
|
Can you not delete this one this time <_<
|
|
|
05/08/2011, 07:16
|
#3
|
elite*gold: 0
Join Date: Jan 2011
Posts: 470
Received Thanks: 97
|
Quote:
Originally Posted by .Ryu
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
|
#4
|
elite*gold: 0
Join Date: Nov 2009
Posts: 322
Received Thanks: 63
|
thats an odd namespace name (:
anyway, nice release fang.
|
|
|
05/09/2011, 01:16
|
#5
|
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
|
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
|
#6
|
elite*gold: 0
Join Date: Jan 2011
Posts: 470
Received Thanks: 97
|
Quote:
Originally Posted by KraHen
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
|
#7
|
elite*gold: 0
Join Date: May 2006
Posts: 297
Received Thanks: 58
|
Quote:
Originally Posted by Spirited
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:
 
|
+1
Dummies:
(for all dummies:
Namespace 数据库 = Namespace Database)
to the creator:
伟大的工作,先生!
|
|
|
05/10/2011, 01:11
|
#8
|
elite*gold: 0
Join Date: Dec 2010
Posts: 341
Received Thanks: 255
|
Quote:
Originally Posted by pintser
+1
Dummies:
(for all dummies:
Namespace 数据库 = Namespace Database)
to the creator:
伟大的工作,先生!
|
哦 我的上帝,我可以使用谷歌翻译的!
|
|
|
05/10/2011, 01:16
|
#9
|
elite*gold: 0
Join Date: May 2006
Posts: 297
Received Thanks: 58
|
上午我好,还是什么?
---btw---
你是假的!
----------
xd
|
|
|
05/10/2011, 02:42
|
#10
|
elite*gold: 0
Join Date: Jan 2011
Posts: 470
Received Thanks: 97
|
其实...我没用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
|
#11
|
elite*gold: 0
Join Date: Sep 2010
Posts: 10
Received Thanks: 4
|
我喜欢在后院下雨时雨水冰雹岩浆。
|
|
|
05/10/2011, 09:19
|
#12
|
elite*gold: 0
Join Date: Jan 2011
Posts: 470
Received Thanks: 97
|
Quote:
Originally Posted by Yoshimitsu™
我喜欢在后院下雨时雨水冰雹岩浆。
|
._. that was a messed up sentence.
K, no more Chinese. lol
|
|
|
05/10/2011, 14:12
|
#13
|
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
|
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..
|
|
|
 |
Similar Threads
|
[Release]CLEAN database + MSSQL cleaning script
11/02/2020 - Dekaron Private Server - 31 Replies
My 666th post!
Ok, so I know everyone is expecting the IPbanV2/3 from me as my next release, but I decided I will do this first, because it took me a lot less time.
LINK (megaupload)
ALL info is deleted, except what is required to run the server with all functions like in the silkbotter's database. Tested by myself, and working.
NOTE: Siege is not added, but you can add it easily with the script. I didn't add siege, because I thought that you will want to set the start time like you...
|
[Release] Einige MSSQL Befehle
02/14/2013 - Flyff PServer Guides & Releases - 55 Replies
.
|
[Release] event handler / system message for 5165 source
05/01/2010 - CO2 PServer Guides & Releases - 10 Replies
i was partially made this and completed by pringle, i dont know if pringle is in here in this forum. but still credit to him.
Go to Program.cs and find:public static Random Rnd = new Random();
Above this add:public static DateTime SystemMsgTime = new DateTime();
scroll down and you found this static void ServerStuff_Execute()
{
try
{
if (World.BroadCastCount > 0 && DateTime.Now > World.LastBroadCast.AddMinutes(1))
{
|
[RELEASE]Web Pack ( MSSQL / ODBC )
05/01/2009 - Dekaron Private Server - 8 Replies
Hello guys.
Here my little Web Script Pack as MSSQL and ODBC version.
I hope , i have found now all bugs and errors and its work.
In the Packs are the follow scripts :
register.php <--- Register Accounts
ranking.php <--- List characters , order by Level and Exp , list only non GMs
guild.php <--- List all guilds . order by members count and list all guild members
|
All times are GMT +1. The time now is 01:21.
|
|