Use LocalDB with APL+Win

General discussions related to using the C# Script Engine in APL+Win.

Moderators: Tech Support, phpbb_admin

Use LocalDB with APL+Win

Postby Ajay Askoolum » October 13th, 2016, 5:32 am

LocalDB is a lightweight single user SQL Server database server with a small foot print.
It can be downloaded from https://www.microsoft.com/en-us/downloa ... x?id=52679

1. Download SQL Server Express Advanced or LocalDB.
2. Choose Custom Installation ... see attached screen shot.

Microsoft SQL Server 2016 Express LocalDB is a feature of SQL Server Express targeted to developers. It is available on SQL Server 2016 Express with Advanced Services.

LocalDB installation copies a minimal set of files necessary to start the SQL Server Database Engine. Once LocalDB is installed, you can initiate a connection using a special connection string. When connecting, the necessary SQL Server infrastructure is automatically created and started, enabling the application to use the database without complex configuration tasks. Developer Tools can provide developers with a SQL Server Database Engine that lets them write and test Transact-SQL code without having to manage a full server instance of SQL Server.

Then you can use the database with []CSE. This sample code provides a basic template.
Code: Select all
        public static void ConnectLocalDB()
        {
            string cn = @"Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True";
            using (SqlConnection myConn = new SqlConnection())
            {
                myConn.ConnectionString = cn;
                myConn.Open();
                string sql = "";
                using (SqlCommand myCmd = new SqlCommand())
                {
                    // Create a Database
                    sql = "CREATE DATABASE FORAPLWIN;";
                    myCmd.Connection = myConn;
                    myCmd.CommandText = sql;
                    myCmd.CommandType = System.Data.CommandType.Text;
                    myCmd.ExecuteNonQuery();
                    // Create a Table
                    sql = "SELECT GETDATE() AS CreationDate INTO myTable;";
                    myCmd.CommandText = sql;
                    myCmd.CommandType = System.Data.CommandType.Text;
                    myCmd.ExecuteNonQuery();
                    // Read the Table
                    sql = "SELECT * FROM myTable;";
                    myCmd.CommandText = sql;
                    myCmd.CommandType = System.Data.CommandType.Text; // Change this for stored procedures
                    using (SqlDataReader myReader = myCmd.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            while (myReader.Read())
                            {
                                Object[] values = new Object[myReader.FieldCount];
                                int fldCount = myReader.GetValues(values);
                                // the vector values now has the columns from the query
                                /*
                                 You will need to pass object values to APL+Win with each iteration
                                */
                            }
                        }
                    }
                }
            }
        }
Attachments
sqlServer2016_LocalDB.png
sqlServer2016_LocalDB.png (29.88 KiB) Viewed 889 times
Ajay Askoolum
 
Posts: 636
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Return to APL+Win & The C# Script Engine

Who is online

Users browsing this forum: No registered users and 1 guest

cron