Need JavaScript expert to convert C# code snippet

CAMPzxzxDeathzxzx
CAMPzxzxDeathzxzx used Ask the Experts™
on
I need to have this converted to JavaScript or TypeScript whichever is easier.

public static SqlDataReader ExecuteReader(string cmd, SqlConnection sqlConnection, SqlParameter[] parameters = null)
        {

            SqlCommand command = null;

            try
            {
                SqlDataReader result;
                command = new SqlCommand(cmd, sqlConnection);
                command.Connection.ConnectionString = DB_Connection;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandTimeout = 0;
                AssignParameters(command, parameters);
                sqlConnection.Open();
                result = command.ExecuteReader();
                return result;

            }
            catch (Exception ex)
            {
//Error trap system
            }

        }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Where is the JavaScript going to run?
leakim971Multitechnician
Top Expert 2014

Commented:
do you mean a Java Script which is totally different?
Java is not JavaScript

Author

Commented:
JavaScript
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Is it possible?
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
It depends what environment you are referring to - see my unanswered question here https://www.experts-exchange.com/questions/29155602/Need-JavaScript-expert-to-convert-C-code-snippet.html#a42926567

If you are referring to the Browser: No you have to go through an intermediary.
If you are referring to NodeJS: Yes

More information will enable us to give you a better answer.
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Even if this were possible to do in the web browser, you definitely would not want to execute this from a web browser. A user can see your source code in the browser, and you would not want them fiddling around with the SQL that you send to your database. Allowing users the ability to modify SQL--either directly or indirectly--is how you end up with corrupted databases.

tl;dr: Run this on the web server and be done with it.

Author

Commented:
I'm thinking NodeJS using mssql or tedious

Author

Commented:
In my C# projects I use a SQL class to limit the amount of code I need to write every time I transact with my DB.  I'm wondering if this can / has been done in NodeJS.

In the C# example above in the question - The only thing I have to write is

SqlConnection sqlConnection1 = new SqlConnection();

                                SqlParameter[] sqlparams1 = new SqlParameter[1];
                                sqlparams1[0] = new SqlParameter("@PermissionId", SqlDbType.Int);
                                sqlparams1[0].Value = ID;

                                SqlDataReader dr1 = _sqlTools.ExecuteReader("usp_GetOfferingBrowseByID", sqlConnection1, sqlparams1);

Open in new window

Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
There are libraries like Sequalize that are probably what you are looking for

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial