Showing posts with label logged. Show all posts
Showing posts with label logged. Show all posts

Monday, March 26, 2012

HELP! sp_send_dbmail error

I'm having trouble sending an email through DBMail. I'm logged in a a SQL Login user named "ServiceUser". I have added this user to the msdb database and as a rolemember to "DatabaseMailUserRole"

USE [msdb]

GO

CREATEUSER [ServiceUser] FORLOGIN [ServiceUser] WITHDEFAULT_SCHEMA=[guest]

GO

USE [msdb]

GO

EXEC sp_addrolemember N'DatabaseMailUserRole', N'ServiceUser'

GO

When I try to send the email:

exec msdb.dbo.sp_send_dbmail

@.profile_name=@.DatabaseMailProfileToUse,

@.recipients=@.EmailAddress,

@.subject=@.Subject,

@.body=@.MessageBody,

@.mailitem_id=@.MYmailitem_id OUTPUT

I get the following error:

Msg 15404, Level 16, State 10, Procedure xp_logininfo, Line 62

Could not obtain information about Windows NT group/user 'ServiceUser', error code 0xffff0002.

I executed the following on msdb and it didn't help:

execsp_changedbowner'sa'

xp_logininfo also returns the error:

EXECxp_logininfo'ServiceUser'

What is wrong? HELP!

My database mail profile was not public! It needs to be public or set to private for the user that is going to access it.

Help! Restore Log while users are logged in.

I have a standby server with log shipping running on it.
We would like to use this standby server, as an ad-hoc
reporting database. This would work great, except for not
being able to perform the restore log at hourly intervals
because users are logged in. Is there a way to restore a
log with users logged into the database. The database is
in read-only mode or warm stand-by because of the
restores. We would like to have somewhat current data to
report from, so restoring the log backups meets that need.
Any suggestions would be greatly appreciatd.No.
Restore requires exclusive access to the DB
--
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org|||Mr. Mitchell is correct that you must have exclusive
access in order to do a restore. But there is a way to
get this to work. Basically you have to kick your users
out for the duration of the restore. The database should
already be in readonly mode, so there shouldn't be an
issue with updating data. Most people think you must
issue kill statements to accomplish this, but you can
alter the database with rollback immediate.
alter database db_name set SINGLE_USER with rollback
immediate
restore log.....
alter database db_name set MULTI_USER
(check BOL for more info)
I've found that this works very well in our situation. I
guess it would depend on how much the db is used for
reporting and what impact it has on users that are
reporting from the db.
>--Original Message--
>No.
>Restore requires exclusive access to the DB
>--
>
>Allan Mitchell (Microsoft SQL Server MVP)
>MCSE,MCDBA
>www.SQLDTS.com
>I support PASS - the definitive, global community
>for SQL Server professionals - http://www.sqlpass.org
>.
>|||Thank you both for your help. I was thinking of a similar
method if a solution was not available, where my restore
job checks to see if people are logged in and takes action
accordingly.
>--Original Message--
>Mr. Mitchell is correct that you must have exclusive
>access in order to do a restore. But there is a way to
>get this to work. Basically you have to kick your users
>out for the duration of the restore. The database should
>already be in readonly mode, so there shouldn't be an
>issue with updating data. Most people think you must
>issue kill statements to accomplish this, but you can
>alter the database with rollback immediate.
>alter database db_name set SINGLE_USER with rollback
>immediate
>restore log.....
>alter database db_name set MULTI_USER
>(check BOL for more info)
>I've found that this works very well in our situation. I
>guess it would depend on how much the db is used for
>reporting and what impact it has on users that are
>reporting from the db.
>>--Original Message--
>>No.
>>Restore requires exclusive access to the DB
>>--
>>
>>Allan Mitchell (Microsoft SQL Server MVP)
>>MCSE,MCDBA
>>www.SQLDTS.com
>>I support PASS - the definitive, global community
>>for SQL Server professionals - http://www.sqlpass.org
>>.
>.
>

Friday, March 9, 2012

Help! Cant Connect - db offline

OK, so I took one of my db's offline for maintenance, then realized that I wanted to be logged in as another user, so I logged out.

Now SS won't let me log in, because every time I try to connect I get:

A connection could not be established...
Reason: Cannot open user default database. Login failed..

The db I took offline is the default db for every single privileged account on the server. Why do I feel like I just locked my keys in the car?

Any help would be greatly appreciated! TIA!Never mind, I figured it out. Logged in via ISQL, and issued:

exec sp_defaultdb '<my sa account>', '<a db known to be online>'

ISQL let me log in, and simply used 'master' instead of the default db that was offline. What reason in the world could there be for EM behaving differently?|||In the future you should set master to be the default database for all users.|||Why? I only do this for the admin group.|||In the future you should set master to be the default database for all users.
Why in the world would you want to do that for application users ?|||Enterprise manager is a good tool to start learning about SQL Server with, but as you get to more and more advanced things, it helps more to use Query Analyzer, or if you are super-hard-core isql or osql. However, in this case, I am not certain how you did get around this. This may take a bit of experimentation for me to figure out. I had thought that any login is sent to the default database, even if just fr a moment, when you have the -d switch set in isql, or a database name set in your connection string. I could very well be wrong.

But essentially, yes. If you drop the database that all of the admin users have as their default database, then you have effectively "locked the keys in the server".|||In the future you should set master to be the default database for all users.

He's just drunk...

and I'm jealous...