Simple scheduler library db for SQL Server in Azure - sql-server

I would like to schedule to run simple SPs to run in my Azure DB. Options: run once and simple recurring by days, weeks, months. As SQL Server Agent is not available in Azure, I am wondering is there any simple scheduling library, db which has this functionality. I would not like reinvent the wheel.
Please do not recommend to run the SQL Server Agent outside and connect to the Azure DB thats not and option.
In case of there is no such T-SQL library (I have to implement it from scratch) could anyone point me how can I implement simple recurring run SP, which runs in every say 5 seconds in Azure.
Thx in advance

If you are fine to execute from WorkerRole use FluentScheduler. Ideally this kind of background job should be executed from worker role only.
However this library can be scheduled from web application also.But I don't prefer this as we may have multiple web roles, take double care while using in web application.
I am using FluentScheduler for my application on Azure (WorkerRole), It works great. It is also very easy to implement.
Example
Schedule<DailyDigest>().ToRunNow().AndEvery(5).Seconds();
Schedule<DailyDigest>().ToRunOnceAt(18, 0).AndEvery(24).Hours();
Schedule<WeeklyDigest>().ToRunOnceAt(DateTime.Now.StartOfWeek(DayOfWeek.Sunday).AddHours(18)).AndEvery(1).Weeks();
In above example, DailyDigest and WeeklyDigest are the classes inheriting from ITASK
public class DailyDigest : ITask
{
public void Execute()
{
//Get Daily digest
}
}
public class WeeklyDigest : ITask
{
public void Execute()
{
//Weekly Digest
}
}
Get this library from github
https://github.com/jgeurts/FluentScheduler
OR
using Nuget Install-Package FluentScheduler

Not built into Azure SQL - but there are 3rd party services that allow scheduling (Aditi and Cotega are mentioned here http://social.technet.microsoft.com/Forums/exchange/en-US/b2ae724f-4509-4c0f-aef4-58ce8be60f1a/is-there-an-equivalent-job-regular-sql-server?forum=ssdsgetstarted)
If you have Worker Roles (or other VMs running in Azure) available - you can roll your own schedule process. This, obviously, involves paying for that compute time.
If this is an option (i.e. you are paying for spinning up a VM) - you also have the option of running your own instance of SQL Server on your own VM and using "standard" SQL Server (with a standard Agent, etc.) - rather than hosting your DBs in Azure SQL. This would be a very expensive alternative...
Personally, I would look at using a Mobile Service to call the SP and then devise a way to schedule a call to the service. Not robust - but quick and dirty and cheep...

Microsoft have just announced Windows Azure Scheduler, which includes a free tier. See the pricing page

Related

Create tenant database programatically

I am having a multi-tenancy application developed with Spring boot. In the master table I hold information about the tenant databases. I am trying to create a service, that receives a row from the master table and creates the database for it. Is there a known way to do this in Spring boot? The only information I can find on internet is creating at start up of the application and this is not desired. The master-tenant table is in a master schema and has the following structure:
The method from the service is as follows:
public void createTenant(TenantDTO tenantDTO) {
tenantepository.save(new Tenant(tenantDTO));
MasterTenant masterTenant = new MasterTenant();
masterTenant.setDbName(tenantDTO.getTenantId());
masterTenant.setDriverClass("com.mysql.jdbc.Driver");
masterTenant.setTenantId(tenantDTO.getTenantId());
masterTenant.setPassword("password");
masterTenant.setStatus(EStatus.ACTIVE.name());
masterTenant.setUserName("root");
masterTenant.setUrl("jdbc:mysql://localhost:3306/"+tenantDTO.getTenantId());
DBContextHolder.setCurrentDb(masterTenant.getDbName());
masterTenantRepository.save(masterTenant);
multiTenantConnectionProvider.selectDataSource(masterTenant.getTenantId());
//create schema + create tables from existing entities or run a script of sql
}
I would need help figuring out the part with create schema and tables.
One Option that I can think of is having a back-end like Jenkins or AWS Lambda to which you can give the request to create the database in your server pool.
In case of choosing a Jenkins job, you have REST API exposed by Jenkins, which you can make use of to trigger the job. As it is more tied to the dev-ops you can use terraform like script in the jenkins job that accepts the tenant id as a parameter to set that as the database name etc.
Some advantages of using a Jenkins job are
The job can be long running
Supports queueing
Can easily integrate with devops and remove those dependencies with the application
API based access to trigger a job, view status and logs etc.

Can I use SignalR with SQL Server Backplace on an existing entity code first database?

According to Scaleout with SQL Server you can use SignalR.SqlServer to keep SignalR synced on a load balancing setup. I have an existing MVC 5 website with its own database created using Entity Code First. The article seems to use a dedicated database with service broker enabled and says not to modify the database.
So do I need to have a separate database for this? I know Entity can be picky if the database schema doesn't match and I worry that if I try to use the SignalR Sql Server package with the existing database that the tables it creates will cause a context changed error.
Also can someone provide me with more information about using the Microsoft.AspNet.SignalR.SqlServer package. The article I linked doesn't give a ton of detail and I don't know if I need to change anything in my hub and groups or if it is all handled automatically.
You should be able to, though you'd likely want to separate your entity framework definitions from signalR. You can either put SignalR in a separate database, or give the two a separate schema.
In terms of configuration, you'll need to make an addition to the Startup class of your web project:
public class Startup
{
public void Configuration(IAppBuilder app)
{
var sqlConnectionString = "connection string here";
GlobalHost.DependencyResolver.UseSqlServer(sqlConnectionString);
this.ConfigureAuth(app);
app.MapSignalR();
}
}

How can I resolve error when trying to launch instance on Amazon RDS?

I'm using the AWS Toolkit in Visual Studio 2013 to attempt to launch a new instance on Amazon RDS. I get through the wizard for creating the new instance and after clicking finish, there is a delay, and then a message appears saying:
Error launching DB instance: DB Security Groups can only be associated with VPC DB Instances using API version 2012-01-15 through 2012-09-17.
Launching different types of instances (SQL Server SE vs MySQL) doesn't seem to help, nor does selecting different versions of the platforms (SQL Server 2008 vs 2012). The only thing that gets it to go through is unchecking the box for "default" in the DB Security Groups area. However, I feel like something is going on here that shouldn't be happening.
Can anyone explain why this is happening and how I can resolve it other than by not setting a default security group? Thank you.
If you created your AWS account recently, you will be using a VPC by default.
It sounds like the API the plugin is trying to use hasn't been updated. The latest version is 1.5.6, and looking at the history it seems like some of these features were added in 1.5.0.
I finally solved it! Since I couldn't use the API that the VS 2013 plugin uses, I had to manually add my IP to the Security Group created for my Elastic Beanstalk.
Go to the console, ec2's security groups configuration
Find the one which description matches your Beanstalk (e.g.: Security Group created for Beanstalk Environment to give access to RDS instances)
Hit Inbound, Edit and add a new rule for All Traffic (I guess HTTP should be enough, but just in case).
In Source, select My IP and Save.

Using nHibernate in a windows service

I want to use nHibernate in a windows service. If the systems boots, it might start my service before the database. In that case, configuration of nHibernate fails and the service crashes. So now I'm wondering how I can check if the database service has already been started. In case it has not yet started, my service should wait a bit and try again later.
If your service always runs on the same machine as SQL Server, You should be using ServiceInstaller.ServicesDependedOn to tell Windows(SCM) that you depend on 'MSSQLSERVER' (the name of service that runs SQL Server).
From MSDN:
A service can require other services to be running before it can
start. The information from this property is written to a key in the
registry. When the user (or the system, in the case of automatic
startup) tries to run the service, the Service Control Manager (SCM)
verifies that each of the services in the array has already been
started.
ServiceInstaller is the class that is used by InstallUtil when it installs your service. Other installation packages including InstallShield also support this windows functionality. Equivalent SC command.
So your service will only start after SQL Server is already running. But even in this case, it might still be a good idea to offload all potentially long running startup procedures to the background thread. Do as little as possible in OnStart method. Ideally you would just spawn a new initialization thread that would take care of NHibernate session factory initialization. If for some reasons you still want to do this in OnStart, then you should consider retrying NHibernate initialization and calling ServiceBase.RequestAdditionalTime to avoid:
Error 1053: The service did not respond to the start or control
request in a timely fashion.
Ideally your service should not depend on the database availability because it might be running on a remote machine. The service is an 'always on' process that should tolerate intermittent database connectivity issues.
No clue if there are better ways, but in your service startup, check for the system uptime. If this is less then let's say 5 minutes, wait for (5 minutes - Uptime) and after that start the rest of the service as you normally would.
See the following for Calculating server uptime gives "The network path was not found"
This is not a solution however for when your service tries to connect to a SQL which is down, however if this happens you want to handle the exception and actually be notified that the SQL is down. Very unlikely you want the service to keep trying without you yourself beeing aware the SQL is down.
You could use ServiceController class and call its static method GetServices() to get the list of services. It will give an array of services, find the right one and check its status.
See ServiceController on MSDN
Currently I am making sure I can establish a connection to the database needed and running a default query (configurable). If this is successful I proceed to start the service.
What I've found in some cases is that even if the MSSQL service is started it doesn't guarantee that you can connect to it and execute queries against it.

windows service application interacting with SQL server database

I have a windows service application that is meant to interact with SQL server database (INSERT, UPDATE, ETC). The windows service application is also multi-threaded.
I created an "App_Data" folder to keep my database and used app.config file for connection information, etc.
After installing and starting the service, nothing happens, the database doesnt get updated, etc.
Has anyone ever written a windows service application that interacts with a database? Kindly advice me on how to overcome this problem..
Thanks
From you've described you don't necessarily have a database problem. What you need is a way to debug your windows service. Particularly the OnStart.
Here's what I often put in the OnStart in a Windows Service written in C#
protected override void OnStart(string[] args)
{
foreach (string arg in args)
{
if (arg == "DEBUG_SERVICE")
DebugMode();
}
#if DEBUG
DebugMode();
#endif
timer.Interval = 1;
timer.Start();
}
private static void DebugMode()
{
Debugger.Break();
}
Now when you want to Debug the OnStart you can add the "DEBUG_SERVICE" command argument from the Service Control panel. Otherwise you'll have to try and attach the debugger manually which might not be in time.
Also note how the I start a timer. This allows a separate thread to do the actual work. This is important because you want the OnStart to finish in a timely fashion. A timer isn't required because some windows services respond to an event like a file watcher but more often then not, it seems polling at intervals is what people do in Windows Services.
As far as I know, the App_Data folder and therefore connection strings pointing to it are only available in ASP.NET web apps and web sites - not in other types of Windows apps.
My recommendation: put your SQL Server database on a database server - can be your local machine and a SQL Server Express database - and connect to that server instance!

Resources