on 04-20-2021 9:45 PM
Hi,
one question, how can I connect to a sql server db with SAPIPRA CLOUD
Is there a guide regarding bd?
Hi luis_sandovalm42,
As of now , We don't have any guide.
Please refer to the custom script to connect to SQL server.
function displayResults(rs) {
let i = 1;
let nbFields = rs.Fields.Count;
let header = ' | ';
for(let k= 0; k < nbFields; k++){
header=header+rs.Fields(k).Name+' | ';
}
irpa_core.core.log(header );
while(!rs.EOF) {
let record = ' | ';
for(let k= 0; k < nbFields; k++){
record=record+ rs.Fields.Item(k) +' | ';
}
irpa_core.core.log(i+':'+record );
i++;
rs.MoveNext();
}
return;
}
try{
var string_connection = "Provider=SQLOLEDB;Server=localhost\\SQLEXPRESS;Database="+database+";UID="+user+";PWD="+password;
irpa_core.core.log("Creating the connection ...");
let oConnection = irpa_core.activeX.create("ADODB.Connection");
let rs = irpa_core.activeX.create("ADODB.Recordset");
oConnection.Open(string_connection);
irpa_core.core.log('Connection successful!' );
// Strings for SQL commands
let select_invoices = "SELECT * FROM [dbo].[INVOICES]";
let select_request = "SELECT [Supplier] ,[Material],[Plant],[Quantity],[PurchasingGroup],[NetOrderPrice] ,[Currency],[PurchasingOrganization] FROM [dbo].[PO]";
let insert_request = "INSERT INTO [dbo].[PO] ([Supplier],[Material],[Plant],[Quantity],[PurchasingGroup],[NetOrderPrice],[Currency],[PurchasingOrganization]) VALUES (10100090,'TG0002',2020,150,001,35,'EUR',2020)";
//show the content of the table: INVOICES table
rs.Open(select_invoices, oConnection);
displayResults(rs);
rs.Close();
// Insert query into a table: PO table
irpa_core.core.log("Doing insert request ....");
rs = irpa_core.activeX.create("ADODB.Recordset");
rs.Open(insert_request, oConnection);
irpa_core.core.log("New data inserted !");
// show the content of the table: PO table
irpa_core.core.log("Supplier - Material - Plant - Quantity - Purchasing Group - Net Order Price - Currency - Purchasing Organization");
rs = irpa_core.activeX.create("ADODB.Recordset");
rs.Open(select_request, oConnection);
displayResults(rs);
rs.Close();
} catch (error) {
irpa_core.core.log('Connection failed: '+ error );
irpa_core.core.log('Connection failed: '+ error.message );
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
11 | |
8 | |
8 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.