angular 2 connect to database

392 views
Skip to first unread message

hassan mohamed

unread,
Oct 4, 2017, 9:32:46 PM10/4/17
to Angular and AngularJS discussion
Hi I want to connect to sql server express  from angular 2 app. I was able to connect to database  in TypeScript app using VS 2013  using the class shown below ( I got it from internet). Now I searched if I can do the same in Angular 2 app but did not find anything similar; when I tried to use the code in angular 2 I get error for ActiveXObject

class DataConnectivity {
    LoadDB() {
        var connection = new ActiveXObject("ADODB.Connection");

        var connectionstring = "Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=AdventureWorks2012;integrated Security=SSPI;Provider=SQLOLEDB";
        connection.Open(connectionstring);
        var rs = new ActiveXObject("ADODB.Recordset");
        rs.Open("select top (20)* from Person.Address", connection);


Sander Elias

unread,
Oct 4, 2017, 9:55:54 PM10/4/17
to Angular and AngularJS discussion
Hi Hassan,

You really should not connect your browser directly to your DB. The security risks are way to high. That is why the server is set up so, that it is very hard to do. (It's not imposible, but it really shouldn't nedone like that!)
What you need is a piece of middleware that sits between your frontend(browser) and your backend(serverr+middleware). There are loads of solutions available for this, and you need to find one where you are comfortable with. Search for REST or GRAPHQL in cmbination with the server you use.
Oh, Pick one of those protocols, and stick wit it. REST is the older more proven technolgy, GRAPHQL is the new way. If you are blank on those, you might want to go with the later, but i suspect the setup of it is a tad harder.

Regards
Sander

Tito

unread,
Oct 5, 2017, 6:35:36 PM10/5/17
to Angular and AngularJS discussion
I connect to my Microsoft SQL Server database using 


Then ip.address/api/addresses I get the data that I need
Reply all
Reply to author
Forward
0 new messages