Announcement

Collapse
No announcement yet.

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.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    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 Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    579 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    334 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    554 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    551 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X