Custom & Proprietary service issue - sql-server

We have a windows 2008 box with few windows services; and the services start-up type is Automatic. The concern is that, not all services (with automatic start up type) starts on successful server restart. Any idea ?
We noticed the aforementioned issue on service particularly custom windows service, SQL server related services.

Each service will need to be troubleshooted separately. Are any errors reported to the Event Log?
Perhaps your service is starting too soon, before other necessary services have been initialized. You may need to set up a dependency or set the Startup type to Automatic (Delayed Start) from the the Services Control Panel.

Related

Why my Windows service only establishes connection with database when SQL Server Service runs under Local System account?

My windows service is using integrated authentication and running under Local System account and got the below exception.
The target principal name is incorrect. Cannot generate SSPI context.
The SQL Server Service is running under domain admin user e.g. "domain\administrator". If I change the SQL Server Service to run under Local System account then it fixes the above error.
Can anyone explain why it's happening like this? We have an InstallShield wizard which installs our application on client side i don't know how we can handle this behavior through the wizard. Also changing the user for SQL Server Service is not realistic as well because the client may not allow it.
Note: Once when my windows service works fine and I revert the SQL Server run under the admin account my service runs fine. I guess there are some permissions are set to the local system account.
Before it, I ran the Kerberos which generated the following script to run and fixed the issue. After this it was not required to change the user for SQL Server Service.
SetSPN -d "MSSQLSvc/FQDN" "domain\machine$"
SetSPN -s "MSSQLSvc/FQDN" "domain\administrator"
Please explain why it's happening and what is the best way to handle the situation?
When running under the Local System account, sql-server registers an spn for every service it controls automatcially up to active-directory, and attempts to unregister them when the service shuts down. The Local System account has the ability to communicate over the network as the computer account and thus can indicate to Active Directory as to when to make changes about itself and the SPN SQL Service wants to register. When you change the SQL Server account over to an AD domain user account, the Local System account immediately loses it's ability to control this; therefore you must manually delete the existing SPNs previously registered for that SQL service by Local System before registering new SPNs. You should now notice why its nice that the SQL server script helpfully calls for a deletion of the old SPN followed by the registration of a new one in order to prevent issues. When this isn't done properly - you'll get an authentication error when the kerberos clients obtain a ticket for the old invalid SPN - because it was never deleted and any Kerberos-aware service will always reject a ticket for a wrong SPN. After you make SPN changes, always be sure to restart the SQL Server service and right after that if you’re testing with a user have that user log out and log back in. This answers your main question here.
Please see this Microsoft document for further reading on the subject: Register a Service Principal Name for Kerberos Connections. There's also a very good youtube video on this exact problem, that's where I learned about it and how to resolve it. Ignore "SSRS" in the title, I've watched the entirety and the guidance applies to any and all services by SQL which have SPNs.
You had a secondary question at the very end of your question regarding what is the best way to handle the situation. If you're talking about solving it programmatically that would be very difficult to answer as all environments are different in some way and you will come across SQL instances running in all sorts of different security contexts. In an online forum like this you would probably get different answers from different people. If this were your only question, I think it would get closed by the moderators for "being primarily opinion-based" and likely to attract spam answers. I would suggest you incorporate some kind of guidance about the problem in some form of a Readme file that you should package with the InstallShield wizard.
Side note: I think you should add the kerberos tag to this question - as SPNs are relevant to Kerberos only - and not to any other authentication protocol.

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!

SQL 2k8 reporting services authentication through DMZ

I have SQL 2k8 server and reporting services installed on a server inside a domain. I also have a webserver that is outside the domain. I'm trying to run a reporting services report from the webserver (either through a URL or the report viewer component).
I have managed to authenticate (as detailed in
this post
), and now the report kind of runs; the reporting service website loads with the 'run report' button and the parameters bar etc, however the report itself doesn't show, and all the images associated with the report web-page (e.g. arrows for 'next' and 'back' and things) don't load. I'm guessing this is because everything points to resources inside the domain, which are unavailable from outside?
To summarise, my question can be stated: how do I run a SQL reporting services report hosted on a machine in a domain, from outside the domain?
Well, this certainly is possible. So something must be not quite right.
If you access the ReportServer.aspx page directly, and supply arguments in the form of a get-request, then you'll get a very spartan looking appearance. Could you clarify the circumstance when you're seeing this barren report? Is it when you use a direct-url, or through the report viewer?

Resources