Job cannot access database after installed as Windows service - c#

I can successfully run my jobs (that need access to an Sql Server database) when I run the Quartz.NET server in dev environment (Visual studio). But when I install the project as a Windows service, I get a login failed error to the database in my job. I have also allowed my service to interact with the desktop.
What am I not setting correctly?

You should check the Windows account your service is running under. Most probably it hasn't got the privileges to connect to your SQL Server, or to access the database. Basically, you have two choices:
Configure your service to run under an account that has a corresponding login in your SQL Server instance.
Add the account as a login in your SQL Server instance.

Related

Publish Web Page on Local Server

I have a Web App developed in Visual Studio Community 2019 utilizing ASP.NET, C# and HTML. I am trying to Publish the App locally so that it can be accessed by other Computer systems within the same server. I can successfully publish the static data (images, boxes, headings, titles, etc.) but the DataGrid on my web page does not displays any data.
I connected the data via connectionString to SSMS which works perfectly via IIS Express, if I run the application by opening Visual Studio. I am looking for a way where I don't require to open and Run the application and all computers within the same server can access it directly.
You can try using SQL Server (User name/password) authentication in connection string instead of Windows Authentication if not already done.
Also you can add the 'IIS APPPOOL\DefaultAppPool' user as a database user in your SQL instance, then providing the proper 'User Mappings' to the databases you need the DefaultAppPool user to access.

Database permissions work differently from a windows service?

I have a console application that also runs as a windows service (see: .NET console application as Windows service)
It runs a stored proc that works on my local db, however over the network it only works as a console app, the service gives "SqlException (0x80131904):Cannot find the object or you don't have permission".
The user account has db owner permissions.
The very first thing the SP does is disable a trigger on a table, that it now says either does not exist or I don't have permission to access.
I am new to windows services, is there something I am missing? Do they work differently in this regard?
Its a sqlserver 2012 instance on another devs machine over the local network.
Connection string:
<add name="XYZ_ConnectionString" connectionString="Data Source=PCNAME\sql2012;Initial Catalog=DB_Name;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
EDIT: I have noticed that an earlier part of the service that does a select on a table from the DB is working correctly, which suggests the connection is working?
Thanks
If the select query is running correctly that seems to be a permission issue on SQL Server on the user excuting the operations.
Given that you are removing a trigger that does requires a different set of permissions that the ones needed to execute a select statement. I would suggest that you make sure the running user is getting proper access to the services, I would use SQL Server Profiler to log all the query and events to the database right after I run the application. In there I would see the queries that are failing and have a better picture of the root of the error.
You're using Windows Authentication (the part of your connection string that reads Integrated Security=SSPI;) so when you run it as a console app it is using your logged in Windows ID to authenticate.
SQL Servers can be configured to use Windows Authentication or "Mixed Mode", which supports a textual username and password (details). Note that the default is to only use Windows Authentication.
If you are able to add Mixed Mode auth to the SQL Server (or it's already enabled) then get the database admin to create a new user and replace the Integrated Security=SSPI; part of your connection string with something like this:
;User ID=*****;Password=*****;
If you are not able to use Mixed Mode auth at the SQL Server (some DBAs are reticent to do this) then you need to configure your Windows Service to start with a Windows Domain account - note that it must be a Domain account, rather than a local Windows account on your PC, because the SQL Server needs to get to a domain controller to authenticate the credentials.
Info on configuring the service's credentials can be found here, but it's little more complex than opening the service in the service manager window, going to the "Logon" tab, and selecting the account that the service should run as.

Login failed for user in SQL Server 2008 for Windows application

I have two PC (both have Win7). On PC "A" I have installed Microsoft SQL Server 2008 and developed a Windows application. On PC "A" my application is running well and there is no connectivity issue.
But when I run this application on PC "B" (connected with PC "B" through LAN and able to share any file) it shows error message login failed for user'....'.
I have already make some possible solution but can't solve it.. Need help
My connection string is:
Data Source=WIN7-PC\PRABHAT;Initial Catalog=plproject;User ID= win7-PC\Prabhat;MultipleActiveResultsets=true
Is there any problem?
The SQL Server error log contains addtional information about failed logins. Look there and find the code that maps to the table listed here: https://support.microsoft.com/en-us/kb/555332
One possible issue is that you are running as a machine account that doesn't exist on machine B. You need the Windows identity to flow from one machine to another and this is typically accomplished with a domain service account. If you want it to work from machine B, you need to access it with an account machine B is aware of. Supplying the User ID is typically for SQL Server authentication, not Windows authentication. You could try adding the password and see if that works.
Here is a breakdown of SQL Connection String syntax: https://www.connectionstrings.com/sql-server/
You need to enable TCP/IP for cross machine SQL SERVER access. Just follow below mentioned steps to ensure whether it is enable or disabled.
Click on window start menu.
Navigate to Microsoft SQL SERVER => Configuration Tool => SQL
Server 2008 Configuration Manager.
In Opened window Navigate to SQL SERVER Network Configuration =>
Protocols for <MSSQLSERVER> (Protocols for your SQL server
instance name)
Check Whether TCP/IP is enabled or not.

SQL Server database is readonly error

I am trying to upgrade one of our web application from Windows Server 2003 to a new box with Windows Server 2012. The application allows us to create multiple instances of another application as virtual directories within a website. Its more like we create an instance of a web application on run time for every signup which is customer specific. Each instance consist of SQL server MDF file that it attaches to SQL server.
The problem I am having is that MDF file is from SQL 2008 and system fails to upgrade it to 2012. If I upgrade it manually then system complains that database is in readonly mode. I have already set application pool identity to Network Service account and I believe it should have sufficient rights to attach/read/write the database. I am unable to reproduce the problem on local system where I am using Windows 8 and SQL 2012. Any help would be appreciated.
Failed to update database "some.MDF" because the database is read-only.
Network service has not part in readonly database configuration.It could depend from login role.Have you check via ssms if login user has been bind to the database and if its has the right permission.
Take a look to the image below:
if not you need to setup right configuration for your customer and so on.
The only way to get it working was by allow Network Service full control permissions using NTFS folder permission dialog.

Starting a windows service on remote machine in different domain

My PC is in Domain A and a remote server in Domain B, I want to restart a service on server from my PC using c# or any other language or script.
Notes:
I am connected to the server via VPN that means i can manually RDP the server and can manually restart the service.
I am not able to access services on server using connect to other computer under action button from local services window.
I have admin rights to the server.
I can't(not allowed) add any component to server.
I have different set of credentials for Remote machine
You should first try the sc command to make sure you're able to start that service remotely using the current permissions and credentials. If that works, take a look at System.ServiceProcess.ServiceController.
When you say you're an admin on the remote machine, I'm assuming that means you're logging in with different credentials. I don't believe either of those will allow you to use alternate credentials -- i.e., the commands will execute with Domain A privileges and those privileges are most likely insufficient for what you're trying to do.
Can you use a batch file? I usually use something like this:
NET USE \\computername\IPC$ /U:domainname\username password
SC \\computername START service

Categories

Resources