SQL Server 2014 - Service Broker: maximum Services - sql-server

I am using SQL Server 2014 using FireDAC in Delphi XE7 to connect to the database.
We need an Event to automatically open a form if some Data where changed in a special Table. Therefor we found the TFDEventAlerter which we used to create a Queue and Service for each User.
UserEvent.Names.Add('QUEUE=qUserEvent');
UserEvent.Names.Add('SERVICE=s' + Username);
UserEvent.Names.Add('CHANGE1=usr;SELECT ID FROM dbo.MsgBox WHERE Status = 'A');
So we have got one Queue and a lot of Services that are listening to that Queue. In general this Setup ist working fine.
But if a lot of Users (550 in my case) are connecting to the database and adding new Services to the Queue we got the Problem that we are running into bad Performance enforced by ThreadPool_Starvation as each Service is blocking a Worker-Thread from time to time.
So does anybody know why there is a limitation using Services for the Service Broker in SQL Server 2014?
Is there another way to use the TFDEventAlerter with 500 Users without creating 500 Services? It seems to me, that we are not using the TFDEventAlerter as it is used to be.

Related

Azure Serverless SQL Serverless Database

I Created SQL Server Database in Azure which is serverless and tried to access it using my SQL Server Management Studio in my local but I couldn't get it work.
It always gives me this message:
I tried to whitelist also my IP in Azure but still I get the same result.
Is there a possible way to make it connect?
Is the database currently online or paused?
I'll repeat the text from #David Browne's link:
If a serverless database is paused, then the first login will resume the database and return an error stating that the database is unavailable with error code 40613. Once the database is resumed, the login must be retried to establish connectivity. Database clients with connection retry logic should not need to be modified.
So;
Assuming the database is paused, this is normal operation
Please read docs
You need to retry after the database starts OR manually pre-start it using the Powershell provided in the link below
https://learn.microsoft.com/en-us/azure/sql-database/sql-database-serverless#connectivity
And yes, you also need to whitelist your IP address as you have already done.
Obviously this flavour of SQL is unsuitable for some types of applications - there is more information in the link - I suggest you read the whole thing.

Connecting to sql database

(I am a sql noob and I just can not figure this out on my own)
For some time now I have been trying to establish a connection to a SQL database in codename one but to no avail. First I tried connecting to a MariaDB database from one.com. All that's needed for the connection is
Database db = Display.getInstance().openOrCreate("databaseName");
if I am not mistaken, but I am guessing this implies that I have somehow already established a connection to the database. This is not the case however so it creates a new .sql file, right? I can recall that you can connect to a database in the services tab in Netbeans. I chose the MySQL(Connector/ J Driver) which should work with MariaDB, or should it? I entered all my data and i says that it can not establish connection to the database.
the error i get
So I thought I might as well try using localhost. I used XAMPP to host a database and connected in the netbeans services tab.
connected?
Now testing was needed to see if this works. I started the SQL journey with this https://www.codenameone.com/manual/files-storage-networking.html#_sql and integrated the part after "You can probably integrate this code into your app as a debugging tool". I changed database name to "mybase" (it's existance can be confirmed in picture 2). Ran the app, opened the dialog, entered "select ID from customers" and got: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: customers) It does not get past the first call to "executeQuery". The customers table definitely exists so what am I missing to establish connection?
I really need instructions to connect to the localhost database and ideally also to the one hosted by my webhost provider.
Thanks,
Jona
The Database class is to access the SQLite DB on the mobile device. To connect to external databases, you'd have to do something different, such as a ConnectionRequest or Socket I think.

NodeJS mssql multiple connections from different users

I'm developing an express-based application that makes some queries to different (different by user!) SQL Server 2008 and 2014 databases. It's different because each user belongs to a different company and each company has its own SQL Server. My app uses an own SQL Server to manage companies and their SQL Server connection string (my app has access to their database servers). I'm using the mssql module.
I've not found a best practice regarding "should I use one SQL Server connection per user session or one connection for each user request".
Coming from a .NET world we had a rule: "one query/function - one connection".
First, the app has to query the own app database to get the SQL Server connection string for the database of the user's company. The user then can retrieve some data from their company's SQL Server (in my app) - like getAccounts(). Each of these functions (each function - not each request in that function!) opens a new connection and closes it after query completion:
let connection = new mssql.Connection(conStr, (err) => {
request.query(queryString, (err, result) => {
if (err)
throw new Error('...');
resolve(result)
connection.close();
});
})
As far as I understand, it should make no (negative) difference if 100 users open and close connections per request (assuming just one request per user at the same time) or if 100 user have 100 opened connections (one per user) for the whole session. At first glance it seems that my approach is less resource hungry since connections are only opened when they are needed (i.e., a few seconds per request).
Am I missing something? What if 200 users access my app at the same time - will I get in trouble somehow?
Thanks in advance!
[EDIT]
As far as I understand,
let connection = new mssql.Connection(...)
will create a new connection pool which will open a new connection when I use something like
connection.connect()
and close all active connections with:
connection.close()
So I'm guessing that best practice in my scenario would be to create one connection pool (new mssql.Connection(..)) per active user, save it in some kind of session store and then reuse it throughout the lifetime of the session.
Is this a good approach?
I just want to avoid one thing: a user gets an error because a connection can't be created.

Send TCP Message in Update/Insert/Delete Trigger

I am building a support ticket system using Sql Server 2014, ASP.Net MVC 5, angular JS etc.
As part of the design I want a way for my system to know when a ticket has been updated, deleted, or created.
That way if a user has a ticket open and it is changed while they have it open I can design the system to force them to refresh the ticket before they themselves can make changes to it, to prevent User B from overriding User A's changes they haven't seen.
Ideally, I'd like to design a TCP Protocol server as a Windows Service and be able to connect to it and send it data from table triggers in Sql Server.
Then the application front end would use Javascript and WebSockets. So the application would be connected to the socket server as well as sql server. When a user opens a ticket I would send a message that user XXY has Ticket 00X open. When a change happens in sql server it tells the server Ticket 00X changed. Then the Socket server tells clients connected to it that are looking at Ticket 00X that it has changed and the javascript prevents a submit until a fresh is done.
But... Can sql server do this at all? Doesn't appear so.
So I'm wondering if it's posisble to build a plugin for SQL Server to enable support for it like PostgreSQL's Notify feature.
Update:
I've discovered User Defined CLR Functions in SQL Server and have managed to get it working. (C#/.Net Framework) I made a static class with some static methods like,
public static int NotifyTicketUpdate(int ticketID)
{
//...
}
Then I registered it in SQL Server,
USE TLCDB;
CREATE ASSEMBLY MyCompanyName_MyDll
FROM 'd:\pathtodll\mydll.dll'
WITH PERMISSION_SET = SAFE;
CREATE FUNCTION XYZ_Notify_Ticket_Updated(#input int) RETURNS int
AS EXTERNAL NAME MyCompanyName_MyDll.UserDefinedFunctions.NotifyTicketUpdated;
Then to call it in SQL, I just do
select dbo.XYZ_Notify_Ticket_Updated(#ticketIDHere);
And it all works. My Static method in c# sends the TCP/IP message to my socket server, the server then checks to see who is looking at that ticket ID and sends them a Ticket_Updated message. The websocket layer running in client javascript sees it, and locks the ticket for updates/saves.
Or you can use Service Broker for handling asynchronous notifications. Not the simplest thing to learn, but lightweight, scalable and already built-in.
You could use CLR, which requires a bit of setup.
You could create an EXE that you can shell with parameters from an SP.
You could implement some standard concurrency. Optimistic vs Pessimistic
So yes, it's possible.

Web Application retrieving datas from SQL Server 2005

I have the follow (and bizzare) situation:
My web application loads some datas (by executing 1 proc) in 8 seconds
My proc, when executed directly on SQL, load in 1 seconds.
Im pretty sure there is no looping in both.
My question is:
Could bad IIS configuration cause this?
Tks.
you might wanna put some word about how ur connecting to your database from your web aplication... Ofc. you get slower results from your web aplication due to your need to connect to DM, read context, transfer it, and cloase conn where on other hand in sql server ur allready connected and data is just there.
But in your case, it is kind of strange to have 800% diference from your aplication and direct sql.
btw, does your application runs on your pc same as sql server or is it on some remote server?

Resources