connecting to a database

Created at 17 Nov 2012, 19:28
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
lec0456's avatar

lec0456

Joined 14.11.2012

connecting to a database
17 Nov 2012, 19:28


I am trying to use the System.Data.SqlClient namespace but it gives me an error.  It says the namespace does not exist and asks if I am missing an assembly.

Do you know whats wrong?

 


@lec0456
Replies

lec0456
18 Nov 2012, 07:19

RE:
lec0456 said:

I am trying to use the System.Data.SqlClient namespace but it gives me an error.  It says the namespace does not exist and asks if I am missing an assembly.

Do you know whats wrong?

 

Thats ok I figured it out!

@lec0456

pedrotduarte
28 Nov 2012, 21:54

RE: RE:
lec0456 said:
lec0456 said:

I am trying to use the System.Data.SqlClient namespace but it gives me an error.  It says the namespace does not exist and asks if I am missing an assembly.

Do you know whats wrong?

 

Thats ok I figured it out!
Hi
 
I was having precisely the same issue as you. Could you share how you did it to make it work? And what database did you use?
 
Thanks

@pedrotduarte

lec0456
29 Nov 2012, 03:55

RE: RE: RE:
pedrotduarte said:
lec0456 said:
lec0456 said:

I am trying to use the System.Data.SqlClient namespace but it gives me an error.  It says the namespace does not exist and asks if I am missing an assembly.

Do you know whats wrong?

 

Thats ok I figured it out!
Hi
 
I was having precisely the same issue as you. Could you share how you did it to make it work? And what database did you use?
 
Thanks
Sure, you need to add a reference to the .net assembly:
//#reference: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Data.dll
 
Then add the sql or oledb objects, depending if you are connecting to sql server or Ms Access:
using System.Data.SqlClient;
using System.Data.OleDb;
 
Everything else will be standard...
 

@lec0456

bhoja
21 Oct 2013, 18:19

RE: RE: RE: RE:

Hi there,

I tried your suggested solution, but I still get a compiler error.  Now I get System.Web version 4.0.0.0 assembly cannot be found.

Did you have a similar issue?

I've also tried to reference Framework v2 System.Data.  This compiles, but the Robot doesn't even start it's run and throw an Error #92946333.

Many Thanks.

 

lec0456 said:

pedrotduarte said:
lec0456 said:
lec0456 said:

I am trying to use the System.Data.SqlClient namespace but it gives me an error.  It says the namespace does not exist and asks if I am missing an assembly.

Do you know whats wrong?

 

Thats ok I figured it out!
Hi

 

I was having precisely the same issue as you. Could you share how you did it to make it work? And what database did you use?

 

Thanks

Sure, you need to add a reference to the .net assembly:

//#reference: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Data.dll

 

Then add the sql or oledb objects, depending if you are connecting to sql server or Ms Access:

using System.Data.SqlClient;
using System.Data.OleDb;

 

Everything else will be standard...

 

 


@bhoja

jhtrader
25 Oct 2013, 21:55

Was there a solution to the problem?

I would be very interested in how you put data into a database from a robot... did you guys ever get this working.  Please share an example that would be great. and very helpful.


cerana
17 Sep 2015, 06:36

Why is this not working? (Visual Studio: OK)

using System.Linq;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Data;
using System.Data.Common;
using System.Data.Odbc;
namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.FullAccess)]
    public class Algoritmus_ceranae : Robot
    {
        protected override void OnStart()
        {
            string myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= E:\\adatbaz.mdb";
            double total = 0;
            int count = 0;
            string mySelectQuery = "Select*FROM árfolyamok";
            OleDbConnection myConnection = new OleDbConnection(myConnectionString);
            OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
            myConnection.Open();
            OleDbDataReader myDataReader = null;
            myDataReader = myCommand.ExecuteReader();
            while (myDataReader.Read())
            {
                count += myDataReader.GetInt32(0);
            }

Manage references: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Data.dll 

                              C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Data.dll 


@cerana

Spotware
17 Sep 2015, 06:51

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.

 


@Spotware

ClickAlgo
19 Sep 2015, 15:03

Microsoft came up with Entity Framework so that you no longer need to do the usual Data Access plumbing to connect to a database, now with Object Relational Mapping (ORM) you can get your data injected direct to a business object class which maps as per your database table structure and allows easy CRUD operations.

Why re-invent the wheel and duplicate code each time.


@ClickAlgo

ClickAlgo
19 Sep 2015, 15:27

RE:

Paul_Hayes said:

Microsoft came up with Entity Framework so that you no longer need to do the usual Data Access plumbing to connect to a database, now with Object Relational Mapping (ORM) you can get your data injected direct to a business object class which maps as per your database table structure and allows easy CRUD operations.

Why re-invent the wheel and duplicate code each time.

Just so you know with Visual Studio and the entity framework, you can use a wizard that will create all your (business objects) entity data models and do all the plumbing code for you to easily select, update, insert and delete into your tables with simple LINQ.


@ClickAlgo

cerana
20 Sep 2015, 16:37

Paul!       

Thank you very much!                                                                                                                                                                                          


@cerana

Vitali Gajdabrus
05 Dec 2018, 22:08 ( Updated at: 21 Dec 2023, 09:21 )

How to write and how to read the "mdb" file MS Access? 
I could not find the answer.  
Please give an example.
Thank.


@Vitali Gajdabrus