Script To Generated The User And Permission
Oct 3, 2005
Here is the simple script, which generated the user and user permission and can be transferred to another database. I think it may useful for new DBA. I just wrote it 2 days ago.
-----------------------------------------------------------------
declare @login varchar(20),
@db_user varchar(20),
@role varchar(30),
@role_mem varchar(30)
print 'USE '+ db_name()
print '-------------------------------------------------------------'
print '--Granting current DB access'
print '-------------------------------------------------------------'
declare add_user cursor for
select b.name as 'login', a.name as 'db_user' from sysusers as a inner join master..syslogins as b
on a.sid = b.sid and b.name <> 'sa' order by a.name,b.name
open add_user
fetch next from add_user
into @login, @db_user
while @@fetch_status = 0
begin
print 'exec sp_grantdbaccess '+''''+@login+''''+','+''''+@db_user+''''
fetch next from add_user
into @login, @db_user
end
close add_user
deallocate add_user
print '-------------------------------------------------------------'
print'--Adding role'
print '-------------------------------------------------------------'
---------add role
declare add_role cursor for
select name from sysusers where issqlrole =1 and gid <> 0
open add_role
fetch next from add_role
into @role
while @@fetch_status = 0
begin
print 'exec sp_addrole '+''''+@role+''''
fetch next from add_role into @role
end
close add_role
deallocate add_role
----------add role members
print '-------------------------------------------------------------'
print '--Adding role members'
print '-------------------------------------------------------------'
declare add_role_member cursor for
select g.name as 'role',u.name as 'name'from sysusers u, sysusers g, sysmembers m
where g.uid = m.groupuid and g.issqlrole = 1 and u.uid = m.memberuid and u.name <> 'dbo' order by g.name,u.name
open add_role_member
fetch next from add_role_member
into @role_mem,@db_user
while @@fetch_status = 0
begin
print 'exec sp_addrolemember '+''''+@role_mem+''''+','+''''+@db_user+''''
fetch next from add_role_member
into @role_mem, @db_user
end
close add_role_member
deallocate add_role_member
Sanjeev shrestha
View 1 Replies
ADVERTISEMENT
Oct 24, 2015
How can i assign permissions to a newly created users as of an existing user?
View 3 Replies
View Related
Oct 1, 2007
Hello
SQL Server 2000 Enterprise Edition SP3
I have an application which uses a login with an encrypted password. Everything works well, no errors in the application.
My SQL Server errorlogs keeps recording:
Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.
I know this message is related to the login with the encrypted password (tracked it with Profiler)
My question: Is it normal that the error log tracks this message because the password is encrypted?
Many thanks!
Worf
View 1 Replies
View Related
Nov 15, 2007
Hello,
Just yesterday I implemented SqlCacheDependencies on my ASP.NET 2.0 web site for SQL Server 2005. My SQL Server 2005 database is in mode 90, mirrored with a second database server. Now I am getting Error 17310 while running very simple statements, but only on a specific table.
We have a table called "tblSchools" which, due to negligence and incompetence, has a maximum size of over 8,000. I plan on fixing that eventually, by splitting all the long varchar(2048) fields off into other tables.
I wanted to use SqlCacheDependencies on this table, for every single column. So I created a DateTime column called LastChanged and created a trigger. I am using LastChanged as a DateTime type instead of a TimeStamp/RowVersion type because I thought it would be more useful.
Here are the changes made:
---------------------------
-- Adding the column...
ALTER TABLE tblSchools
ADD
LastChanged DateTime Null
GO
-- The program uses this stored procedure to watch the "LastChanged" column.
CREATE PROCEDURE [apCacheWatchSchool]
@SchoolID int
AS
select LastChanged from dbo.tblSchools where SchoolID = @SchoolID
GO
-- Any updates on the table cause the LastChanged column to be updated with getdate()
CREATE TRIGGER [UpdateLastChanged_TS]
ON [dbo].[tblSchools]
AFTER INSERT,UPDATE
AS
BEGIN
SET NOCOUNT ON;
update [dbo].[tblSchools]
set LastChanged = getdate()
where SchoolID in (select SchoolID from inserted);
END
GO
---------------------------
After adding this column and the trigger and s-proc, any update to any row in tblSchools fails with error 17310. It CANNOT set LastChanged to anything. It has to remain NULL. I was able to perform the following operation (as long as the tblSchools.LastChanged updating trigger [UpdateLastChanged_TS] was disabled): "update tblSchools set SchoolName = 'ZZZZ' + SchoolName where SchoolID = 185" -- so, it's not some kind of row length limit. I think it's a limit on # of columns that can be dealt with. I don't really know.
I don't know where the problem is occurring. I am just telling you why. I got around the problem (temporarily) by simply having the trigger update a DateTime column in another table, and having the SqlCacheDependency watch that column in the other table. No biggie.
As for moving some of the enormous varchar columns off of tblSchools... I don't really care enough. I guess that's why it's been like this for so long.
So, my problem is fixed, I just wanted to submit this bug report so you can at least fail gracefully in the next version of SQL Server.
I have the log/txt/mdmp files available, and can provide them upon request; they're too big for this form, sorry. Please contact me at plushpuffin AT wwddfd.com if you have any questions.
View 1 Replies
View Related
May 6, 2007
Hi,
I grant read/update/insert permission on the speicific columns of the table on the users. I want to write the T-SQL to retrieve what permission/column permission does the user have.
View 1 Replies
View Related
Mar 13, 2008
Hi,
I am new to reporting service. I set up a couple reports and deployed them to Report Manager. I then add my colleague's Windows user account to the report folder so she can view the reports. When she tried she got Login failed error. I have to go into the SQL database and manually add her account into the Login and assign permission to her for each database or stored procedure involved. Then she can view the reports. We do want to control who can view what reports and later hopefully who can view which part of a report. But do I have to manually give permission to each user account/or group in the SQL server? There got to be a better way to do this I feel. Can we use just one account to talk to the database and let what we set in report manager control who can view what? Thank you very much for your help in advance.
View 5 Replies
View Related
Jun 7, 2001
Hi all,
I need to run a query that would return all users with sa privileges at a server level. Sysusers has the db users for each individual databaase. But I need to list all sa users and the databases they have rights to. Looks like I may need a cursor...not sure. If any of you can help me build this query, I would really appreciate it. Thanks.
View 2 Replies
View Related
Sep 10, 2000
I have a nightly job that restores a production database to a reporting server. I have some report- related stored procedures
that need to run on the reporting server once the database is restored. However, during the restore, the permissions for the
reporting stored procs get deleted and replaced with the production permissions, which are useless in this case.
Is there a script or system stored procedure I can schedule to run after the nightly restore that will also restore user
permissions? Thanks, Frank.
View 1 Replies
View Related
Apr 28, 2006
Hi, Does anyone has a script to get user permissions on all tables?
Thanks
View 8 Replies
View Related
Apr 25, 2008
Hi,
I newly created one database (using creat database testdb ). After that i created login name and password for that database ( using create login login1 with password = 'pass1'; use testdb; command) and i created user for that login name ( using create user user1 for login login1 command).
Then i connected testdb database using login1. But when i trying to create table in that database, it thrown error. Anyone please tell me that how to assign all privileges to the user user1?
Sathish kumar D
View 3 Replies
View Related
Apr 1, 2007
Hi,I have installed sql server 2005 express on a Windows xp system with windows authentification. I did this with my administrator account (dan). When i start sql server management studio, i see: user name: myserverdan .Now i want to create a new login, so i rightclick on 'logins' in 'Security' of 'Database'. I take an existing windows-account, but when i click on OK, i get the error: user does not have permission to perform this action (error 15247).I also tried to delete a login, but same error.Any help would be appreciatedT.
View 2 Replies
View Related
Aug 2, 2007
I am trying to use a query analyzer to perform a task and I keep getting this message....how do I get around this?
View 1 Replies
View Related
Mar 18, 1999
Hello Everyone,
I need your input. When, if ever, should programmers be given the 'sa' login. The reason that I ask is because a group of three developers have approached me asking for the 'sa' login so they could write stored procedures and do some database level tasks. I am relatively new to data admin and I am under the opinion that I should probably just alias their login to 'dbo' on the one database that they are developing their app for.
What do you guys think about this.
Thanks in Advance,
Terry
View 2 Replies
View Related
Jan 15, 2015
I try to attach a database mdf file to Microsoft SQL server 2014 on Amazon Elastic Computing Cloud, EC2, but fail with the following message, "User 'guest' does not have permission to run DBCC checkprimaryfile. (Microsoft SQL Server, Error: 2571)" The ID I use to REMOTE login has administrator rights and I have chosen to "run as administrator"
View 1 Replies
View Related
Sep 14, 2006
hi,I am getting the following error while trying to add a remote server.The user does not have permission to perform this action.The command i used is:exec sp_addlinkedserver 'remote_server_name'What is the solution?Regards,Kalaivanan.
View 1 Replies
View Related
Jul 19, 2007
Hi All
I kind of hit the wall with this message.
Here is what I do:
select * from sys.dm_db_index_physical_stats(24,null,null, null, null)
My server is 64 bit 2005, sp2.
That's the message I get.
I am loging int as Administrator.
Does anybody know what needs to be done?
View 4 Replies
View Related
Aug 30, 2007
Dear,
What minimum permission do i need to grant to a Remote Login to create a linked server.
Regards
Sufian
View 7 Replies
View Related
Jan 31, 2007
hey people having a nightmare getting asp.net 2.0 to work with sql server 2005 express, bit of a newbie with it. trying to display a table from my sql database and every time i run the aspx table im getting this error. User does not have permission to perform this action.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: User does not have permission to perform this action.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): User does not have permission to perform this action.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734995
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +33
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +628
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +170
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +130
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +496
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +83
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1770
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +41
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360 keep getting the user permission error, even though it says on the management console that i have access to the database any ideas? rob
View 3 Replies
View Related
Jul 26, 2001
Hi,
I'm trying to run the Bulk Insert statement but in order for me the run it, i need to have the sysadmin permission. Can someone show me how to grant sysadmin permission to my SQL Server user? This is really urgent. Thank you in advance.
View 1 Replies
View Related
Oct 16, 2007
I originally installed SQL Server Express 2005 on my computer using Windows Authentication mode, and discovered when I tried to add another user/login that I didn't have permission to do so. This is rather odd as the windows account that I installed SQL server with is the system admin for the computer.
I have successfully changed the login mode to mixed, and have tried to login in as "sa", but it appears that "sa" was given some sort of password (did SQL server automatically generate one?), and I don't know what it is. When I go into command prompt and try to change the password, it says that it cannot alter the login 'sa' because it does not exist or I do not have permission (i'm pretty sure it's the later, as 'sa' shows up on the list of logins in SQL server express).
I'm so stuck! Please help!
View 6 Replies
View Related
Jun 26, 2007
There's something I can't quite figure out about user creating
The application that I'm currently working on is interacting with DB, therefore every time you use application you need to login as user which is fine. The problem is that certain users should be able to create new users and the new user may even have the same level of permissions as the one that's creating it ( like admin creating another admin acount or some like that).
Question is how can I allow users to create these user with giving them as few permissions as possible.
If there's is somewhere a code sample on the net I would appreciate the link.
View 1 Replies
View Related
Feb 7, 2006
I just installled the Visual web developer - express addition. When I try to add aSQL database to my project it gives the following error - "User does not have permission to perfor this action" . Can someone please help?
View 4 Replies
View Related
Feb 27, 2008
Hi,
Any body please give me some TSQL Stored procedure for
creating an SQL user and to give db access permission to all the databases available on a the server.
Mujeeb
View 5 Replies
View Related
Dec 1, 2006
I am using Microsoft Visual Web Developer 2005
Here are the steps I used to create my database
Tools -> connect to database -> Select datasourse - Microsoft SQL Server (SqlClient) -> Server name - comp4_8SQLExpress -> Log on to the server €“ Use Windows Authentication -> Connect to a database -> Select or enter a database name €“ MyDataBase
comp4_8 - is the name of my computer. I am using Windows XP Professional SP2. Login as administrator without password.
Now about the problem I have. On local machine everything is great! But I hosted my website and got this error. The question is how to give permission to this user to connect to my database.
Cannot open database "MyDataBase" requested by the login. The login failed.
Login failed for user 'ANGELINAASPNET'.
View 6 Replies
View Related
Dec 26, 2006
in SQL server 2005, Database User's permission will be overriden by the database Role's permission or ottherwise? For example, a userA is owner of table AA so it has all permisions on table AA but the user is a member of GroupB but group B has no permission to access to Table AA. What happen on User A?. has it permission to access to table BB or not? How can I find document or example about this?
Please help me, thanks so much
View 3 Replies
View Related
Feb 24, 2008
Hello,
I am trying to grant solely the SELECT privilige to a particular user and to a particular database.I am using Sql server management studio express to do this and SQL Server 2005.
I have created a new login and set the server roles to public, then on the user mapping page, I have checked the box next to the table I wish the user to access and have selected the database membership role - public.
Next, On the Table Properties, I have added the user on the Permissions Page and Selected "Select" under the grant column
When I click on effective permissions, the select command does not show and when I try to login with that user, the table does not display.
What I am doing wrong?
Thanks
View 7 Replies
View Related
Aug 28, 2015
I have a new instance (SQL 2012) and I am trying to create a cube but it retrieves the error: Either the 'NameUser' user does not have permission to create a new object in 'NameServer' or the object does not exist. I am not the DBA but I got privilege as administrator in my instance. I even checked the propierties (right click on the analysis service instance) and in security there is my name as well..
View 4 Replies
View Related
Mar 25, 2007
Folks, This is driving me nuts. I posted the other day on a related issue, which I belive turned out to be a file permission. I am trying to test my asp.net site under IIS before deploying it. I am now getting the above message which breaks on the opening page on opening a connection to the sql server database. I have permissions set on the database for MachineNameASPNET and NT AUTHORITYNETWORK SERVICE as Ken Tucker suggested. Still getting the message. This certainly looks like a sqlserver permission issue but I am at a loss as to how to grant IIS or the specific web app permission to access the database. Any assistance is truely appreciated. I have spent way to many hours on this. If you don't have the answer but can suggest a resource where I can research it that would help also. Thanks
View 4 Replies
View Related
Feb 7, 2003
Hello Everyone,
I have an web application where the users has to run SQL scheduled jobs from the webpage. How to assign permission to a specific user to run specific jobs without making them a member of a Sysadmin role?
Any ideas you all smart people?
Thanks in advance!
Jannat.
View 3 Replies
View Related
Jun 18, 2007
hi ,
I am getting some problem in using group in sql server login.
i have two NT groups in windows.i) developer and tester
I added a user Lalit in both gruop. I want to give db_owner permission on a particular database(Employee) to developer group and data_denyreader and deny_writer on same database(Employee) to tester group.
Now when i logging in to sql server using Lalit(windows authentication) iam not able to access the database(Employee).
Now my concern is that Lalit should have full access to the employee database when entered as developer user and limited access to employee database when entered as tester user.
how can i achieve this set up????
Please do help.
Thanks a lot in advance !!!!!!!!!!!!!!!!!!
View 1 Replies
View Related
Apr 7, 2008
Can somebody tell me without pointing to any other link how to grant Create Procedure permission to DB user.
View 3 Replies
View Related
May 1, 2015
best possible way to provide truncate table permission to a SQL Server Database user (ddl_admin role cannot be granted to the user in my case)
View 3 Replies
View Related
Jul 26, 2007
I have user XY in SQL 05. I would like to find all stored procedures, where user XY has permission for executing. Is there any way to find it than look in every stored procedure?
Thanks for tips
View 4 Replies
View Related