Grr >.> More Errors >

05/12/2010 03:38 -Shunsui-#1
Well this is my createcharacter class for 5165 and i Type its Name Choose Body Size Wen I click Enter It Gives me The Error Try again i just cant find wats the problem

Code:
using System;
using Source_Project.GameSystem;
using Source_Project.Structures;
using MySql.Data.MySqlClient;

namespace Source_Project
{
    public partial class Database
    {
        public static string CreateCharacter(string Account, string Name, ushort Body, byte Job)
        {
            MySqlConnection Conn = GetConnection(); Conn.Open();

            try
            {
                MySqlCommand Cmd = null;
                string ret = "";
                bool exist = false;
                try
                {
                    lock (Conn)
                    {
                        Cmd = new MySqlCommand("SELECT * FROM `cq_users` WHERE `Name` = '" + Name + "'", Conn);
                        MySqlDataReader DR = Cmd.ExecuteReader();

                        while (DR.Read())
                        {
                            ret = "Name in use.";
                            exist = true;
                        }
                        DR.Close();
                    }
                    Conn.Close();

                    if (exist)
                        return ret;
                }
                catch { }
                byte avatar = 1;
                if (Body != 1003 || Body != 1004)
                    avatar = 201;
                ushort Str = 0, Agi = 0, Vit = 0, Spi = 0;
                GetInitialStats(Job, ref Str, ref Agi, ref Vit, ref Spi);
                ushort HP = (ushort)(Vit * 24 + Str * 3 + Agi * 3 + Spi * 3);
                string Inventory = "";
                string Skills = "";
                Conn = GetConnection();
                lock (Conn)
                {
                    Cmd = new MySqlCommand("INSERT INTO `cq_users` (Account,Name,Avatar,Body,Hair,Job,Str,Agi,Vit,Spi,CurHP,Inventory,Skills) VALUES ('" + Account + "','" + Name + "'," + avatar + "," + Body + "," + (410 + (Program.Rnd.Next(5) * 100)) + "," + Job + "," + Str + "," + Agi + "," + Vit + "," + Spi + "," + HP + ",'" + Inventory + "','" + Skills + "')", Conn);
                    Cmd.ExecuteNonQuery();
                    Cmd = new MySqlCommand("UPDATE `cq_accounts` set `Character` = '" + Name + "' WHERE `AccountID` = '" + Account + "'", Conn);
                    Cmd.ExecuteNonQuery();
                }
                Conn.Close();
            }
            catch { return "Error! Try again."; }

            return "ANSWER_OK";
        }
    }
}
## EDIT this is it writing the line...
[Only registered and activated users can see links. Click Here To Register...]
05/12/2010 09:25 -impulse-#2
Database connections are not supposed to have a long life. You need to configure your mysql to be able to hold like 500+ connections at one time,
and use this piece of code for a mysql connection.

Code:
using(MySqlConnection Conn = new MySqlConnection("THE STRING HERE"))
{
Conn.Open();

//Use the connection

}

//Connection is already disposed after moving out of the using statement.
05/12/2010 11:44 _Emme_#3
Wouldn't it just be easier to learn how to code yourself?
05/12/2010 12:47 .Summer#4
Quote:
Originally Posted by EmmeTheCoder View Post
Wouldn't it just be easier to learn how to code yourself?
To learn code, dosn't just take 1day.
What would you say, if you had a problem on breathing and then take to the hopsital.
Then the doctor say: "Wouldn't it be easier if you learn to breath"
05/12/2010 14:11 _Emme_#5
Quote:
Originally Posted by .Summer View Post
To learn code, dosn't just take 1day.
What would you say, if you had a problem on breathing and then take to the hopsital.
Then the doctor say: "Wouldn't it be easier if you learn to breath"
Sigh..

This guy have been asking for help for the most simple problems ever for over a month, within 2 days of online tutorials and reading you would be able to solve half of the problems he have been making threads about.

Or, even worse, I believe a non coder would understand this problem just by taking the little time to read it through, but no, this guy needs to make a thread on a forum.

He could of for example:
Read the problem through, it's clearly saying the connection must be valid and open.
Quote:
Okay, is the connectionstring valid, no typos etc? Hm, no. Alright, have I opened it (connection.Open(); ) - no I have not, there's my mistake!
[Only registered and activated users can see links. Click Here To Register...]
Quote:
Connection must be valid and open C#
The google one got me tons of answers, wouldn't that take less time than making a thread and waiting for a response?




What I'm saying is not that we should not help people, but when there's faster to use google for such a common problem, do so.