Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to connect to SQLite natively in Ninjascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to connect to SQLite natively in Ninjascript

    I want to set up a SQLite database and write to it in Ninjascript...

    Probably I can create an ODBC interface, but would like to use the native SQLite interface, such as

    using System.Data.SQLite;

    but I'm not sure where to find that...when I set up References?

    It is evidently not included in the Ninja Install.

    Also, Ninja already uses SQLite...is there a Using statement available from the Ninja libraries?

    thx

    #2
    Hello llanqui,

    Thanks for your post.

    No, there are no NinjaScript specific Using Declarations for working with an SQLite database.

    Setting up and accessing a database in a NinjaScript goes outside of the scope of support we would be able to provide you with in the Support Department at NinjaTrader.

    You could do further research on working with SQLite in C# to find more information on how to accomplish your specific goal.

    This forum thread will be open for other community members to share their insights on this topic and unsupported code.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      after looking at the SQLite C# libraries I decided to use SQL Server Express instead...

      microsofts sqlite interface recommended using only the SQLite primitive data types...with SQL Server I won't have any data conversion problems, etc...

      Comment


        #4
        Hello IIanqui,
        Are you able to share your code for the SQL Server Express ? I am trying to implement alert logging and indicator values from a chart.
        Many thanks in advance,
        AH

        Comment


          #5
          I haven't coded that yet....but probably ODBC would be the easiest

          my database is currently SQLAnywhere and it works fine with ODBC and Ninja C#

          but SQL Server Express would be much better, not in terms of performance or features, but simply that it has a lot of support now and in the future

          Comment


            #6
            Thanks for the response.
            Can we pool our resources together to work on this feature ?. At least writing to a SQL database from Ninjascript.
            If this can work, I have a developer who is willing to try it out with strategies and attempt to send it to alert logs.
            My contact details is [email protected].
            Cheers,
            AH

            Comment


              #7
              Sorry, my email address is [email protected]

              Comment


                #8
                A developer would know....it is not hard....just connect to the database with ODBC then write to it....

                but I don't write to the SQL Database...I'm not sure if you want to do that while live trading

                I use the database to hold configuration data and load it when ninja starts, so the connection is not persistent...only a few seconds at startup time

                Comment


                  #9
                  here is how simple the connection is, after the connection

                  region SQLConnection
                  private void ConnectSQL()
                  {
                  DB = new OdbcConnection ("DSN=CRC Analytics;UID=dba;Pwd=thispwd;");

                  try
                  {
                  DB.Open();
                  }
                  catch(OdbcException e)
                  {
                  Log ("Coach Load -- DB Connect Error= " + e.ToString(), NinjaTrader.Cbi.LogLevel.Alert);
                  DB_Connected = false;
                  }
                  }

                  private void DisconnectSQL()
                  {
                  try
                  {
                  DB.Close();
                  }
                  catch(OdbcException e)
                  {
                  Log ("Coach Load -- DB Close Error = " + e.ToString(), NinjaTrader.Cbi.LogLevel.Alert);
                  }

                  }
                  #endregion​

                  Comment


                    #10
                    after the connection you can write to the database with ODBC Insert/Update/Delete commands

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by lightsun47, Today, 03:51 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post lightsun47  
                    Started by 00nevest, Today, 02:27 PM
                    1 response
                    8 views
                    0 likes
                    Last Post 00nevest  
                    Started by futtrader, 04-21-2024, 01:50 AM
                    4 responses
                    44 views
                    0 likes
                    Last Post futtrader  
                    Started by Option Whisperer, Today, 09:55 AM
                    1 response
                    13 views
                    0 likes
                    Last Post bltdavid  
                    Started by port119, Today, 02:43 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post port119
                    by port119
                     
                    Working...
                    X