Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Programming
You last visited: Today at 18:01

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Request] How to connect a C# application to Sql Server

Discussion on [Request] How to connect a C# application to Sql Server within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jun 2006
Posts: 457
Received Thanks: 67
[Request] How to connect a C# application to Sql Server

Ok, the title is very vague, I'll provide the details here.

I have a MVC3 application that requires connection to a database. I have already created the necessary tables in a database in Sql Server 2008, and i have verified that MSVS2010 can detect my DB. My question is how to make my application query the DB?


When i worked on another solution, there is a sub project in that solution that handles all database connections. This project seems to be able to populate classes based on tables in the DB. Can someone enlighten me how is that done?

Though this is not directly associated with the topic CO programming. I do think that the knowledge is common across all types of programming (especially CO ps development).

EDIT: if possible, can one please provide me screenshots/video of how to properly connect my application to a sqlserver DB and query it. I don't mind what is the methodology used; be it direct query using sql commands or using C#.Net LINQ features.
shitboi is offline  
Old 01/12/2012, 17:46   #2

 
jackpotsvr's Avatar
 
elite*gold: 20
Join Date: Oct 2008
Posts: 328
Received Thanks: 43
Quote:
Originally Posted by shitboi View Post
Ok, the title is very vague, I'll provide the details here.

I have a MVC3 application that requires connection to a database. I have already created the necessary tables in a database in Sql Server 2008, and i have verified that MSVS2010 can detect my DB. My question is how to make my application query the DB?


When i worked on another solution, there is a sub project in that solution that handles all database connections. This project seems to be able to populate classes based on tables in the DB. Can someone enlighten me how is that done?

Though this is not directly associated with the topic CO programming. I do think that the knowledge is common across all types of programming (especially CO ps development).

EDIT: if possible, can one please provide me screenshots/video of how to properly connect my application to a sqlserver DB and query it. I don't mind what is the methodology used; be it direct query using sql commands or using C#.Net LINQ features.
What kind of SQL server do you use? I experienced small differences between seperate SQL servers. Like mysql has some small differences to microsft sql. Though those diffrences aren't that hard to find out.

The connecting is not hard as it may sound, there are lots of tutorials based on that on youtube(look ), but if you're more experienced in programming you can also find the neccesary script parts in SQL-based conquer online private server sources and copy the parts you need. ;]

Ofcourse you either can write it all by yourself, but I guess you won't be asking around here if you'd be capable to do so. :P

If you want to use a tutorial on youtube, make sure you use the one for your SQL.

Hope this makes it a little more clear
jackpotsvr is offline  
Old 01/13/2012, 05:44   #3
 
Arco.'s Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
Why don't you take a looka t nHibernate?
It's what I use for my server->database handling.
Arco. is offline  
Old 01/13/2012, 06:20   #4
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,377
Quote:
Originally Posted by Arco. View Post
Why don't you take a looka t nHibernate?
It's what I use for my server->database handling.
Doubt he wants to get that advanced right now as he's just trying to figure out basic database functionality in C#...

Nhibrinate is lots of fun (albetros has lovely examples of it in use) but it's far from simple. Lots of stuff to make sure is configured correctly and then still gotta ensure that all of your tables are mapped properly to get them to work.

It's fantastic but far from an entry level solution.
pro4never is offline  
Old 01/13/2012, 09:14   #5
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Really simple example.
Code:
using System.Data.SqlClient;

public class MssqlWrapper
{
    private string connectionString;
    public MssqlWrapper(string connectionString)
    {
        this.connectionString = connectionString;
    }

    private SqlConnection CreateConnection()
    {
        return new SqlConnection(connectionString);
    }
    public MssqlWrapper Insert(string Table, string Column, object Value, out bool Success)
    {
        try
        {
            SqlConnection con = CreateConnection();
            con.Open();
            SqlCommand cmd = new SqlCommand("INSERT INTO " + Table + " (" + Column + ") " +
                                     "Values (" + Value + ")", con);
            cmd.ExecuteNonQuery();
            Success = true;
        }
        catch
        {
            Success = false;
        }
        return this;
    }
}
I don't have a username is offline  
Old 01/19/2012, 22:35   #6
 
elite*gold: 0
Join Date: Dec 2009
Posts: 25
Received Thanks: 1
What "I don't have a username" has posted will work if ur connecting to a MSSql server but if u need to connect to a mysql server u need to get the mysql connecter(Search google) and add the mysql.data.dll as a reference in ur project. Best thing here is that the same code applies for both ways of connecting.
konsowa is offline  
Old 01/19/2012, 23:24   #7
 
gabrola's Avatar
 
elite*gold: 0
Join Date: Dec 2006
Posts: 1,039
Received Thanks: 1,335
Quote:
Originally Posted by konsowa View Post
What "I don't have a username" has posted will work if ur connecting to a MSSql server but if u need to connect to a mysql server u need to get the mysql connecter(Search google) and add the mysql.data.dll as a reference in ur project. Best thing here is that the same code applies for both ways of connecting.
SQL Server = MSSQL
He's not asking about MySQL.
gabrola is offline  
Old 01/24/2012, 15:46   #8
 
elite*gold: 0
Join Date: Aug 2011
Posts: 5
Received Thanks: 0
yyy Thank's
ineedthe is offline  
Reply

Tags
c#, database, programming


Similar Threads Similar Threads
[Request]connect without using Hamachi
10/22/2011 - SRO Private Server - 2 Replies
I have my server set up and running fine. i have a static ip but i am on a router router is DMZ'd and Router Firewall is off server ip's are all set to 192.168.11.13 and server starts and runs fine i am able to connect from my laptop when people try to connect to my server they get C9 error after putting in the image verification code. i do not run hamachi and neither does anyone i know.
[REQUEST] Guide To Connect To Emulated Server
08/26/2010 - SRO Private Server - 4 Replies
Can someone please make a little guide on how to connect to an emulated server. I mean - What files are needed - How to redirect to the ip - ... Thanks
facebook application mafia wars [request]
11/26/2009 - Facebook - 4 Replies
anyone knows a hack on this? or how to hack this one? thanks
[Request]CoEmu how do ppl connect
08/15/2009 - CO2 Private Server - 9 Replies
What do people have to do to connect to my CoEmu v2 server. I need a guide. (Made this thread half asleep) Also how do I make myself GM.. noobish talk I know I had to ask quick. I'll look at this tomorrow..
[Request] Aimbot source which I can connect on P-Server
08/09/2009 - CO2 Programming - 5 Replies
Can someone give me aimbot source like COoperative which I can work on P-Servers?



All times are GMT +2. The time now is 18:01.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.