|
You last visited: Today at 17:18
Advertisement
[C#] SQL Connect
Discussion on [C#] SQL Connect within the SRO Private Server forum part of the Silkroad Online category.
12/26/2015, 08:46
|
#1
|
elite*gold: 0
Join Date: Jun 2012
Posts: 239
Received Thanks: 26
|
[C#] SQL Connect
hey guys im editing a released source and iam trying to make SQL connection
read from config.cfg file but when i do it like this
PHP Code:
public static SqlConnection con = new SqlConnection(@"Server="+sqlCon.server+";Database="+sqlCon.db+";User Id="+sqlCon.id+";Password="+sqlCon.pw+";MultipleActiveResultSets=True;Trusted_Connection=true");
and config.cfg like this
PHP Code:
[Connection] IP=127.0.0.1 LoginPort=15779 Locale=22 Version=188 [Client] Username=gm123 Password=gm123 CharName=[GM]BOT Captcha=0 [SQL] ServerName=WIN-123WIN\SQLEXPRESS id=sa pw=123456 db=LOG_DB
it wont work
Full sqlCon.cs
PHP Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Threading.Tasks; using System.Data.SqlClient; namespace Yuri { public static class sqlCon { public static string server = ""; public static string db = ""; public static string id = ""; public static string pw = ""; public static SqlConnection con = new SqlConnection(@"Server="+sqlCon.server+";Database="+sqlCon.db+";User Id="+sqlCon.id+";Password="+sqlCon.pw+";MultipleActiveResultSets=True;Trusted_Connection=true"); public static void ChangeDB(string DBName) { try { switch (DBName) { case "Acc": con.ChangeDatabase("SRO_VT_ACCOUNT"); break; case "Shard": con.ChangeDatabase("SRO_VT_SHARD"); break; case "Log": con.ChangeDatabase("LOG_DB"); break; case "Event": con.ChangeDatabase("Yuri"); break; } } catch (Exception ex) { Console.WriteLine("ChangeDB function has some errors." + ex.ToString()); } } public static void exec(string query) { try { SqlCommand com = new SqlCommand(query, con); com.ExecuteNonQuery(); } catch (SqlException Ex) { Agent.TypeLog("MSSQL Error -> Function exec(" + query + "), exception catched : " + Ex.ToString()); } } //read string public static string ReadString(string query) { string strResult = null; try {
SqlCommand com = new SqlCommand(query, con); com.CommandType = CommandType.Text; strResult = (string)com.ExecuteScalar(); } catch (SqlException Ex) { Agent.TypeLog("MSSQL Error -> Function ReadString(" + query + "), exception catched : " + Ex.ToString()); } return strResult; } public static int ReadInt(string query) { int nResult = 0; try { SqlCommand com = new SqlCommand(query, con); com.CommandType = CommandType.Text; nResult = (int)com.ExecuteScalar(); } catch (SqlException Ex) { Agent.TypeLog("MSSQL Error -> Function ReadInt(" + query + "), exception catched : " + Ex.ToString()); } return nResult; } public static string[] getSingleArray(string query) { try {
SqlDataAdapter SqlAD = new SqlDataAdapter(); SqlAD.SelectCommand = new SqlCommand(query, con); DataSet ds = new DataSet(); SqlAD.Fill(ds);
DataTable dt = ds.Tables[0];
if(dt.Rows.Count != 0) { string[] arr = new string[dt.Rows[0].ItemArray.Length];
arr = InitializeArrays.InitStringArray(arr);
DataRow row = dt.Rows[0]; //first array
for (int i = 0; i < dt.Rows[0].ItemArray.Length; i++) { arr[i] = row[i].ToString();
} return arr; } } catch (SqlException Ex) { Agent.TypeLog("MSSQL Error -> Function getStringArray(" + query + "), exception catched : " + Ex.ToString()); } return null; } }
}
config.cs
PHP Code:
sqlCon.server = cfg.IniReadValue("SQL", "ServerName"); sqlCon.id = cfg.IniReadValue("SQL", "id"); sqlCon.pw = cfg.IniReadValue("SQL", "pw"); sqlCon.db = cfg.IniReadValue("SQL", "db");
any hint how to make it read server name from the .cfg ?
****************
but like this it works
PHP Code:
public static SqlConnection con = new SqlConnection(@"Server=WIN-123WIN\SQLEXPRESS"+sqlCon.db+sqlCon.id+sqlCon.pw+"; MultipleActiveResultSets=True;Trusted_Connection=true");
|
|
|
12/26/2015, 10:37
|
#2
|
elite*gold: 0
Join Date: Apr 2015
Posts: 1,444
Received Thanks: 1,371
|
Test this:
Code:
public static iniFile cfg = new iniFile("config.cfg");
public static SqlConnection con = new SqlConnection(@"Server=" + cfg.IniReadValue("SQL", "ServerName") + ";Database=" + cfg.IniReadValue("SQL", "db") + ";User Id=" + cfg.IniReadValue("SQL", "id") + ";Password=" + cfg.IniReadValue("SQL", "pw") + ";MultipleActiveResultSets=True");
If that don't work, change name on your config.cfg to config.ini
|
|
|
12/26/2015, 13:39
|
#3
|
elite*gold: 0
Join Date: Jun 2012
Posts: 239
Received Thanks: 26
|
didn't work
changed to .ini still nothing
|
|
|
12/27/2015, 03:44
|
#4
|
elite*gold: 71
Join Date: Mar 2011
Posts: 1,594
Received Thanks: 1,099
|
Please use google, stop using ready-to-use ***** from eirene auto bot cause it's ****.
|
|
|
12/27/2015, 06:12
|
#5
|
elite*gold: 0
Join Date: Jun 2012
Posts: 239
Received Thanks: 26
|
Quote:
Originally Posted by Skipper*
Please use google, stop using ready-to-use ***** from eirene auto bot cause it's ****.
|
ok i will , maybe i needed a place to start or some thing to try on what is going on my until i learn how to do it on my own
i still need to know how to do it
|
|
|
12/28/2015, 01:02
|
#6
|
elite*gold: 166
Join Date: Apr 2009
Posts: 2,339
Received Thanks: 2,654
|
Your problem is not about connecting to sql, you can't read an .ini file...
|
|
|
12/28/2015, 01:23
|
#7
|
elite*gold: 0
Join Date: Jun 2012
Posts: 239
Received Thanks: 26
|
Quote:
Originally Posted by sarkoplata
Your problem is not about connecting to sql, you can't read an .ini file...
|
"you" means me or the prog ? feeling a bit trolled
|
|
|
12/28/2015, 01:28
|
#8
|
elite*gold: 166
Join Date: Apr 2009
Posts: 2,339
Received Thanks: 2,654
|
i won't waste time explaining, just give tv info over skype, i'll do it
|
|
|
|
Similar Threads
|
Minecraft Hamachi Server Failed to connect to the server Connection refused connect
01/26/2012 - Minecraft - 1 Replies
Hallo zusammen,
Wir haben einen Hamachi Server, den wir für den Multiplayer Mode von Minecraft verwenden. Bis jetzt ging alles einwandfrei, doch seit heute geht nix mehr. Der Ersteller vom Hamachi Server ist zwar online, doch wenn ich in den Server in Minecraft reingehe, kommt die Fehlermeldung:
Failed to connect to the server
Connection refused: connect
Was geht da schief?
Danke im Voraus.
MfG kugelmanno
|
Connect DB connect connection refused HILFE!
02/27/2011 - Metin2 Private Server - 4 Replies
Ich habe mir einen server mit 2 Channels erstellt und beim starten kommt immer dieser fehler -.-
in navicat hab ich versucht alle tabellen zu reparieren, aber bei information_shema kommt acces diened
Bild:
http://img825.imageshack.us/i/picturers.jpg/
Server startet und kann mich auch einloggen
|
proplem (connect: connect refused)
02/20/2010 - Metin2 Private Server - 5 Replies
hi ich habe ein porplem wenn ich mein server starte steht als erstes 8 felher meldungen udn dan ungefähr 11 mal connect: connect refused dan dauert es aufeinmal voll lange bis ich mich einlogge
|
All times are GMT +2. The time now is 17:18.
|
|