Is it possible to create a Repeater to show data from an external DB (SQL Server)?
Hi @avillarg !
What you need is the Wix-Fetch method.
It gives you the ability to communicate with 3rd-party services and import data from external sources.
Check it all out - here .
Doron.
Doron, I use the Wix-Fetch method to get the data. This is the detailed problem:
I need to show the data from a SQL Server DB in a Repeater. To do this, I insert the data in a DataBase Collection (colProspectos) using two functions. The quantity of data I retrieve is erratic: Some times I get 30, other times 100 registers. It should be 200 that is the number that the external database has. I suspect I have problems with the use of async / await. Where is the error???
1. I have a Backend function to get the data from a RestApi:
export async function getAllProspectos()//genera el json de todas los prospectos existentes en la tabla de la BD SQL
{
console.log(“10 Inicia Get function”)
const url = ’ https://restvanyplasapp2.azurewebsites.net/api/Prospecto/ ';
console.log("Url: " + url);
try
{
console.log(“12 Inicia Try”)
let response = await fetch (url, {method: ‘get’});
let data = await response.json();
console.log(“13 Final Try”)
return data;
}
catch (err)
{
console.log(err)
}
console.log(“14 Final Get function”)
}
2. In the page , I use this function :
export async function buttonActualizarProspectos_click(event)
{
//1. Delete collection
await deleteAll(“colProspectos”)
.then(result =>
{
$w(“#datasetProspectos”).refresh();
});
//2. Insert data from Rest Api into Collection
const AllInfo = await getAllProspectos();
for ( var i = 0; i < AllInfo.length; i++)
{
let toInsert =
{
“idProspecto”: AllInfo[i].IdProspecto,
“idTipoCliente”: AllInfo[i].IdTipoCliente,
“empresa”: AllInfo[i].Empresa
}
await wixData.insert(“colProspectos”, toInsert)
.then(results =>
{
let item = results;
})
. catch (err =>
{
let errorMsg = err;
})
}
$w(“#datasetProspectos”).refresh();
}
Hey
If you get 30 sometimes and 100 some other time from Azure I would say that it is a timeout problem you have between Wix Code and Azure. When I have solutions like this I tend to make the call and only get smaller amounts of data and schedule the execution of it to get like 10 records at a time but every 5 minutes until all records are stored and updated.
Otherwise if you only need three fields in your Wix Site you should check if you only get those three fields from Azure of if you actually get like 50 fields. Minimize the query in Azure to just return the fields you need and the response object will be smaller and go faster.
I don’t see any errors in your code.
Next time you paste code in the forums please mark all the code and select CODE icon which is far right icon in the toolbar and it will be much more easier to read.
Thank you Andreas. The Data from Azure often varies, so I need to have a procedure that update easiliy the Collection. So it cannot be with a manual execution. How could I modify my code to get the delay between loads of each 10 records, as you suggest?