I have a webapp designed in asp.net mvc that sends emails via smtp no problem via on click event. But i need a way to automatically check every month for a certification if it is expired and email that user. I am reading sql server or windows service. Which do you recommend and could you provide your link for me to read up on it. Thanks.
Why bother? Sql Server doesn't care about the expiry date...
Joking aside, you'll probably notice that there are a number of internal certs that come with Sql Server that have expired. MS doesn't care about those but you should probably make sure you ignore them in any alert you receive.
You could use a policy (SSMS\Management\Policies) to alert you, something like:
Declare #object_set_id Int
Exec msdb.dbo.sp_syspolicy_add_object_set #object_set_name=N'Certs_ObjectSet', #facet=N'Certificate', #object_set_id=#object_set_id Output
Select #object_set_id
Declare #target_set_id Int
Exec msdb.dbo.sp_syspolicy_add_target_set #object_set_name=N'Certs_ObjectSet', #type_skeleton=N'Server/Database/Certificate', #type=N'CERTIFICATE', #enabled=True, #target_set_id=#target_set_id Output
Select #target_set_id
Exec msdb.dbo.sp_syspolicy_add_target_set_level #target_set_id=#target_set_id, #type_skeleton=N'Server/Database/Certificate', #level_name=N'Certificate', #condition_name=N'', #target_set_level_id=0
Exec msdb.dbo.sp_syspolicy_add_target_set_level #target_set_id=#target_set_id, #type_skeleton=N'Server/Database', #level_name=N'Database', #condition_name=N'', #target_set_level_id=0
Go
Declare #policy_id Int
Exec msdb.dbo.sp_syspolicy_add_policy #name=N'Certs', #condition_name=N'Certs', #execution_mode=0, #policy_id=#policy_id Output, #object_set=N'Certs_ObjectSet'
Select #policy_id
Related
I am trying to determine the application that is using a specific session ID in an Oracle 11g database. I can find the service name of the session id using this query
select SID, SERVICE_NAME
from v$session
where SID = <sessionID here>;
Unfortunately, several applications use this service name to connect to the database. Is there another table/query that I can use to determine which application is using this session ID?
There are other columns in V$SESSION that might be useful, e.g.:
select username, osuser, logon_time, status, program, module, client_identifier, client_info
from gv$session
where sid = <sessionID here>;
However it is up to your application to set or override the last four values.
For example, a session started from SQL*Plus shows program as something like sqlplus#client_host (TNS V1-V3) and module as SQL*Plus. SQL Developer shows both values as that name. A JDBC connection will have something like 'JDBC Thin Client' for both by default, but the application can override those and/or set client_identifier and client_info if it chooses to. As can a Pro*C application, which defaults to both program and module looking something like exe_name#client_host (TNS V1-V3).
As SQL Developer is using JDBC, that is overriding both program and module with it's own value; and SQL*Plus is overriding the default module value.
So if the application using the session ID you're interested in has configured any of those values you should get a pretty good idea of what it is. And if it hasn't then you may still get clues about the kind of application (e.g. JDBC). The osuser might be useful too.
See SYS_CONTEXT and the DBMS_APPLICATION_INFO and DBMS_SESSION packages for more about how an application can set those values.
I have a web server and its session state is stored in a Sql Server. I need to change the timeout to use an external time source. How would I do this?
Ok, it's not hard to do it. I suppose you're able to read that data from the table - related, as you said, to some User Preference - and to put this data in an int:
int myTimeout = [... read from DB];
It's enough to add this line after the login procedure has been completed (or even during the procedure):
Session.Timeout = myTimeout;
Note: the Timeout is in minutes.
I've specified the user of my application pool to be SERVER4\IUSR_SERVER4. And then I added this user to the SQL Server. But when I try to connect to the database I get the following error:
Server Error in '/BSHHD' Application.
Cannot open user default database. Login failed.
Login failed for user 'SERVER4\Administrator'.
What's driving me mad is there's no user named SERVER4\Administrator. What do I have to do in order to be able to properly connect to this SQL Server database from my website?
P.S. I think this is related with Membership authentication. Now I need to find out how Membership accesses SQL Server and where the login credentials are specified
The thing is, the app pool user is not necessarily the user you use to connect to MSSQL (as a guy in the comments already stated). After seeing your connection string, this is probably the case, and maybe, just maybe, the problem is not the user but it's default database.
I've had this error in the past: Try setting the user you use in the connection string (clerk's) default database to something else. This error is common when you've set a default database for a user before and now the database doesn't exist anymore or is having some problems.
You can change the user's default database using something like this:
Exec sp_defaultdb #loginame='clerk', #defdb='dok'
You can also use something like this but I've never used it:
ALTER LOGIN SQLLogin WITH DEFAULT_DATABASE = AvailDBName
Also, there's no need to set the integrated security to false because it is the default value already. I hope this helps =)
I kind of new to SQL Server, I always used access db for my sites.
I created a SQL Server on my local computer and now I want to take this db and transfer it to the server. In access all I had to do is, take the mdb file and put it on the server and change the connection string. How can I transfer the SQL Server db to the server?
Is there any file to put on the server ?
Also the connection string isn't a folder but a local computer like this:
Data Source=my-PC;Initial Catalog=storeSQL1;User ID='my-PC\com';Password='';Trusted_Connection=YES;
Who can provide me this connection string for the server (the hosting company) ?
The easiest way would probably be to create a backup of the database on your local machine, then restore that backup on the new server.
Roadmap is:
Do simple backup-restore to move user databases to target server.
Create script on source server, that can recover permissions and login-users pairing
Restore the CLR and TRUSTWORTHY security for databases, that using unsafe assemblies, simpliest way is (in proper DB):
exec sp_changedbowner 'sa' --sa just for example
ALTER DATABASE dbname SET TRUSTWORTHY ON
Enjoy
Depending on your version of SQL Server here is a good article that outlines all the ways to move a SQL Server Database.
http://blogs.msdn.com/b/sreekarm/archive/2009/09/11/move-a-database-from-one-server-to-another-server-in-sql-server-2008.aspx
As for getting the connection string yes the hosting company would provide you with that. Where is the database hosted, you could check their knowledge base articles or if it's an in house data base I'm sure a dba could provide you with that information. It won't change much from what you have but it will change.
I'm not sure what tools your using, but to start you need to do a dump or backup of your current database on your machine. After you do that then you can do and import which should create all the tables and import any data you have.
After the data exists on the server then as far as the connection string, you just need to say the Data Source is the server ip address or host name and change your User ID and Pass to match that server.
If you need more details on any part of this process, post what tools your using and what your environment looks like and I would be more than happy to assist you.
In my opinion the best way to do that is to detach the db from one server(pc), copy the files to the second one and then attach them on the second server/pc.
To detach:
USE master;
GO
EXEC sp_detach_db #dbname = N'AdventureWorks2008R2';
GO
To attach:
USE master;
GO
CREATE DATABASE MyAdventureWorks
ON (FILENAME = 'C:\MySQLServer\AdventureWorks2008R2_Data.mdf'),
(FILENAME = 'C:\MySQLServer\AdventureWorks2008R2_Log.ldf')
FOR ATTACH;
GO
As per this how-to, I've successfully configured IIS on my XP-SP3 dev box for SQL Server 2008 Express to save ASP.NET session state information. I'm just using SQL Server because otherwise on every recompile, I was losing the session state which was obnoxious (having to re-login). But, I'm facing an annoying issue in that every time I restart SQL there's this error, and sometimes one or two other very similar friends:
The SELECT permission was denied on the object 'ASPStateTempSessions',
database 'tempdb', schema 'dbo'.
To fix the error, I just open Management Studio and edit the User Mapping for the login/dbo I'm using on the ASPState db, and re-add tempdb to that user with all but deny permissions. Apparently, once the right permissions are there, ASP.NET is able to automatically create the tables it uses. It just can't run that CreateTempTables sproc until the right security is there.
THE QUESTION...
Is there a way to not have to re-do this on every restart of the SQL Server?
I don't really care right now about keeping the temp data across restarts, but I would like to not have to go through this manual step just to get my web app working on localhost, which uses session state variables throughout. I suppose one could resort to some kind of stored procedure within SQL Server to accomplish the task for this machine when the service starts, to not have to do it manually. I'd accept such an answer as a quick fix. But, I'm also assuming there's a better recommended configuration or something. Not seeing an answer to this on the how-to guide or elsewhere here on StackOverflow.
Both answers seem valid; but with most things Microsoft, its all in the setup...
First uninstall the ASPState database by using the command:
aspnet_regsql –ssremove –E -S .
Note:
-E is to indicate you want to use integrated security connection.
-S informs what SQL server and SQL instance to use, and the "." (dot) specifies default local instance
Then re-install using the command:
aspnet_regsql –ssadd –sstype p –E -S .
Note:
The sstype has three options, t | p | c ... the first "t", tells the installer to host all stored procedures in the ASPState database, and all data in the tempdb. The second option "p" tells the installer to persist data to the ASPState database. The last option "c" allows you to specify a different 'custom' database to persist the session state data.
If you reinstall using the "-sstype p" you then need only to supply datareader/datawriter to the ASPState database for the user that's making the connection (in most cases, the application pool's identity in IIS).
The added benefit of persisting the data is that session state is retained even after a restart of the service. The only drawback is that you need to ensure the agent cleanup job is pruning old sessions regularly (it does this by default, every minute).
Important:
If you are running a cluster, you must persist session data. You're only option is to use sstype 'p' or 'c'.
Hope this sheds light on the issue!
For the record, I did find a way to do this.
The issue is that the tempdb is recreated from the model db each time the service restarts. The gist of the solution is to create a stored procedure that does the job, and then make that procedure run at startup.
Source code (credit to the link above) is as follows:
use master
go
-- remove an old version
drop proc AddAppTempDBOwner
go
-- the sp
create proc AddAppTempDBOwner as
declare #sql varchar(200)
select #sql = 'use tempdb' + char(13) + 'exec sp_addrolemember ''db_owner'', ''app'''
exec (#sql)
go
-- add it to the startup
exec sp_procoption 'AddAppTempDBOwner', 'startup', 'true'
go
Well done for finding the strangest way possible to do this.
The correct answer is as follows:
use master
go
EXEC sp_configure 'Cross DB Ownership Chaining', '1'
go
RECONFIGURE
go
EXEC sp_dboption 'ASPState', 'db chaining', 'true'
go