TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
SeethaPartha
NA
89
30.7k
Integrate SQL server in angular 2 project
Nov 25 2017 7:18 AM
I completely done with creating angular 2 project which was given in this link.
But in that HTTP part, Need to add external server instead of In-MemorywebAPI. I am not sure how to proceed further with SQL Server db data for CRUD operation.
import { Injectable } from '@angular/core';
import { Observable} from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { data } from './Data';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
const config = {
user: 'sa',
password: 'Server@2009',
server: '172.20.10.95', // You can use 'localhost\\instance' to connect to named instance
database: 'sample',
options: {
encrypt: true // Use this if you're on Windows Azure
}
}
const value=1;
const sql = require('mssql')
(async function () {
try {
let pool = await sql.connect(config)
let result1 = await pool.request()
.input('input_parameter', sql.Int, value)
.query('select * from peoplemaster where id = @input_parameter')
console.dir(result1)
// Stored procedure
// let result2 = await pool.request()
// .input('input_parameter', sql.Int, value)
// .output('output_parameter', sql.VarChar(50))
// .execute('procedure_name')
// console.dir(result2)
} catch (err) {
// ... error checks
}
})()
sql.on('error', err => {
// ... error handler
})
@Injectable()
export class PeopleinfoService {
constructor( private http: HttpClient) { }
}
I tried like this by insatlling mssql from npm. But it shows error like below
Can anyone help with clear procedure of how to connect with SQL db using API and perform required action in angular CLI
Reply
Answers (
3
)
How to check if angularjs app is online using mobile number?
Cannot read property , undefined in node js