Showing posts with label insert. Show all posts
Showing posts with label insert. Show all posts

Wednesday, March 28, 2012

Persian Date

i want to insert persion date to sql database.Can any one helpme

regards dhanya

I can suggest you to use standart datetime string format
[yyyy-mm-dd Thh:mm:ss:mmm (no spaces)]
when inserting the value to the sql. When you read it back you may convert it to a format that you wish.

Regards
Zubeyir

Friday, March 23, 2012

permissions problems with trigger script

CREATE TRIGGER trg_audit_version
ON dbo.syscomments
FOR INSERT, UPDATE, DELETE
AS
SELECT * INTO versionaudit
FROM @.@.version;
GO

SE sqlsvr_audit;
GO
--
CREATE TRIGGER trg_audit1
ON dbo.syscomments
FOR INSERT, UPDATE, DELETE
AS
SELECT * INTO audit1
FROM dbo.syscomments;
GO
--

USE sqlsvr_audit;
GO
--
CREATE TRIGGER trg_auditlogins
ON dbo.syscomments
FOR INSERT, UPDATE, DELETE
AS
SELECT * INTO auditlogins
FROM dbo.syslogins;
GO
--

USE sqlsvr_audit;
GO
--
CREATE TRIGGER trg_audit_sysobjects
ON dbo.sysobjects
FOR INSERT, UPDATE, DELETE
AS
SELECT * INTO auditsysobjects
FROM dbo.sysobjects;
GO
--
USE sqlsvr_audit;
GO
--

CREATE TRIGGER trg_audit_files
ON dbo.sysfiles
FOR INSERT, UPDATE, DELETE
AS
SELECT * INTO auditfiles
FROM dbo.sysfiles;
GO
--

USE sqlsvr_audit;
GO
--

CREATE TRIGGER trg_audit_users
ON dbo.sysusers
FOR INSERT, UPDATE, DELETE
AS
SELECT * INTO auditusers
FROM dbo.sysusers;
GO
--

USE sqlsvr_audit;
GO

I keep getting these syntax and permissions errors with MS SQL Server 2000:

Server: Msg 170, Level 15, State 1, Procedure trg_audit_version, Line 7
Line 7: Incorrect syntax near '@.@.version'.
Server: Msg 229, Level 14, State 5, Procedure trg_audit1, Line 6
CREATE TRIGGER permission denied on object 'syscomments', database 'sqlsvr_audit', owner 'dbo'.
Server: Msg 229, Level 14, State 5, Procedure trg_auditlogins, Line 6
CREATE TRIGGER permission denied on object 'syscomments', database 'sqlsvr_audit', owner 'dbo'.
Server: Msg 229, Level 14, State 5, Procedure trg_audit_sysobjects, Line 6
CREATE TRIGGER permission denied on object 'sysobjects', database 'sqlsvr_audit', owner 'dbo'.
Server: Msg 229, Level 14, State 5, Procedure trg_audit_files, Line 7
CREATE TRIGGER permission denied on object 'sysfiles', database 'sqlsvr_audit', owner 'dbo'.
Server: Msg 229, Level 14, State 5, Procedure trg_audit_users, Line 7

Can anyone help me out here and how to fix these problems with my script? Thanks!Here's what BOL says..

Note Because SQL Server does not support user-defined triggers on system tables, it is recommended that no user-defined triggers be created on system tables.|||Thanks. Besides using the SQL Profiler trace utility is there a method to custom script in T-SQL changes made to these tables ? Oracle allows one to do so and since I am fairly new to SQL Server would be great if a custom way to do this on a periodic basis for monitor security of the databases. Thanks|||SQL Address that in it's next release with the service broker

http://www.informit.com/articles/article.asp?p=327394&seqNum=5

right now the only thing you can do is to restrict access and do compares of 2 database catalogs....

Monday, March 12, 2012

permissions for new user to use stored procedure

Using SS2000 SP4. If I have a table and revoke select, insert, update and
delete to public on the table. Then create a new user and don't give them an
y
permissions to the table. If I create stored procedures to select from,
insert into, update and delete from the table do I only have to give execute
permissions on the stored procedure to the new user for the user to be able
to execute those stored procedures? Am I correct in saying that the new user
doesn't have to have any kind of permissions on the table itself?
Thanks,
--
Dan D.That's correct. Indeed, you didn't need to revoke or deny anything on the
underlying tables, since a user has no permissions on an object by default.
All you have to do is grant EXEC permission on the proc.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"Dan D." <DanD@.discussions.microsoft.com> wrote in message
news:D2083411-5A89-4F04-B1A5-373403FE75EC@.microsoft.com...
Using SS2000 SP4. If I have a table and revoke select, insert, update and
delete to public on the table. Then create a new user and don't give them
any
permissions to the table. If I create stored procedures to select from,
insert into, update and delete from the table do I only have to give execute
permissions on the stored procedure to the new user for the user to be able
to execute those stored procedures? Am I correct in saying that the new user
doesn't have to have any kind of permissions on the table itself?
Thanks,
--
Dan D.|||Wouldn't the user have permissions on the table because they are in the
'public' role by default?
Also, is the same true with views? If the user has select permission to the
view they don't need select on the underlying table?
Thanks,
--
Dan D.
"Tom Moreau" wrote:

> That's correct. Indeed, you didn't need to revoke or deny anything on the
> underlying tables, since a user has no permissions on an object by default
.
> All you have to do is grant EXEC permission on the proc.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
> ..
> "Dan D." <DanD@.discussions.microsoft.com> wrote in message
> news:D2083411-5A89-4F04-B1A5-373403FE75EC@.microsoft.com...
> Using SS2000 SP4. If I have a table and revoke select, insert, update and
> delete to public on the table. Then create a new user and don't give them
> any
> permissions to the table. If I create stored procedures to select from,
> insert into, update and delete from the table do I only have to give execu
te
> permissions on the stored procedure to the new user for the user to be abl
e
> to execute those stored procedures? Am I correct in saying that the new us
er
> doesn't have to have any kind of permissions on the table itself?
> Thanks,
> --
> Dan D.
>|||Let's say you create a table. By default, there are no permissions on the
table - even to the public role. Same goes for any other object.
You can grant permission on a view without granting permission on the
underlying tables. (This gets messed up if you're not the owner of the
underlying tables, though.)
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"Dan D." <DanD@.discussions.microsoft.com> wrote in message
news:EC40014C-0943-4CC3-9FDD-BFE610495BFD@.microsoft.com...
Wouldn't the user have permissions on the table because they are in the
'public' role by default?
Also, is the same true with views? If the user has select permission to the
view they don't need select on the underlying table?
Thanks,
--
Dan D.
"Tom Moreau" wrote:

> That's correct. Indeed, you didn't need to revoke or deny anything on the
> underlying tables, since a user has no permissions on an object by
> default.
> All you have to do is grant EXEC permission on the proc.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
> ..
> "Dan D." <DanD@.discussions.microsoft.com> wrote in message
> news:D2083411-5A89-4F04-B1A5-373403FE75EC@.microsoft.com...
> Using SS2000 SP4. If I have a table and revoke select, insert, update and
> delete to public on the table. Then create a new user and don't give them
> any
> permissions to the table. If I create stored procedures to select from,
> insert into, update and delete from the table do I only have to give
> execute
> permissions on the stored procedure to the new user for the user to be
> able
> to execute those stored procedures? Am I correct in saying that the new
> user
> doesn't have to have any kind of permissions on the table itself?
> Thanks,
> --
> Dan D.
>|||I understand. Thanks.
--
Dan D.
"Tom Moreau" wrote:

> Let's say you create a table. By default, there are no permissions on the
> table - even to the public role. Same goes for any other object.
> You can grant permission on a view without granting permission on the
> underlying tables. (This gets messed up if you're not the owner of the
> underlying tables, though.)
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
> ..
> "Dan D." <DanD@.discussions.microsoft.com> wrote in message
> news:EC40014C-0943-4CC3-9FDD-BFE610495BFD@.microsoft.com...
> Wouldn't the user have permissions on the table because they are in the
> 'public' role by default?
> Also, is the same true with views? If the user has select permission to th
e
> view they don't need select on the underlying table?
> Thanks,
> --
> Dan D.
>
> "Tom Moreau" wrote:
>
>

Permissions for BULK INSERT?

I'm trying to do a BULK INSERT into a SQL Server 2005 db from an aspx page. When I try to run the page, to insert into [myTable], I get:
The current user is not the database or object owner of table 'myTable'. Cannot perform SET operation.
But here's the kicker: if I use Server Management Studio to log into the same database, using the same credentials, and run the same query, it works fine.

My connection string looks like this:

connectionString="data source=myLocalMachine; initial catalog=myCatalog; user=joe; password=joe;" providerName="System.Data.SqlClient"
Can anybody tell me why it works when I log in via SMS, but not when I try the same query from my aspx? I'm totally stuck.

Thanks!I am no SQL Server 2005 expert, but as far as I am aware, running BULK INSERT from Server Management Studio will be using different user credentials than running the process from your ASP.NET page. As far as I understand it, user joe needs to have BulkAdminprivileges. Or, you need to termporarily impersonate an account whichhas those privileges.

Reading the documentation onBULK INSERT may help, as well asPermissions of Fixed Server Roles.

Saturday, February 25, 2012

Permission issues

Dear all,

I have 500 tables in a database.

How can i grant select ,update and insert permission to a user on all 500 tables of the database at once.

Thanks

Mohd Sufian

The fixed database role db_datareader will work for SELECT.

You can use a cursor. ...might want to use sp_executesql

DECLARE @.User sysname

DECLARE @.Table nvarchar(500)

DECLARE @.cmd nvarchar(2000)

SET @.User = 'MyUser'

SET @.cmd = ''

DECLARE GrantUser CURSOR

LOCAL

FAST_FORWARD

FOR

SELECT s.Name + + '.' + o.name

FROM sys.objects o

INNER JOIN sys.schemas s

ON o.schema_id =s.schema_id

WHERE type = 'U'

IF EXISTS (SELECT * FROM sys.sysusers WHERE name = @.User)

BEGIN

OPEN GrantUser

FETCH NEXT FROM GrantUser INTO @.Table

WHILE @.@.FETCH_STATUS = 0

BEGIN

SET @.cmd = ''

SET @.cmd = ' GRANT SELECT ON ' + @.Table + ' TO' + @.User

SET @.cmd = @.cmd + ' GRANT UPDATE ON ' + @.Table + ' TO' + @.User

SET @.cmd = @.cmd + ' GRANT INSERT ON ' + @.Table + ' TO' + @.User

EXEC (@.cmd)

FETCH NEXT FROM GrantUser INTO @.Table

END

CLOSE GrantUser

DEALLOCATE GrantUser

END

|||

If this is SQL SERVER 2005, you can grant all these permissions at the database level itself.

So,

GRANT INSERT ON DATABASE::Database_Name to User_Name

GRANT UPDATE ON DATABASE::Database_Name to User_Name

GRANT SELECT ON DATABASE::Database_Name to User_Name

You must be connected to the database on which you are granting the permissions

Monday, February 20, 2012

Permission error when trying to INSERT data

I have a user trying to insert a record into a table on my SQL 2000 server.
When she tries to do the insert she gets a message "Insert permissions denie
d
on object 'mytable', database 'mydatabase', owner 'dbo'". This user is a
member of an Active Directory group on my network. The AD group has rights t
o
the database on my SQL Server. The AD group has select, insert, update and
delete rights to the table in question. Yet even after all of this she is
still unable to insert records into this table.
What could be causing my problem? We recently changed the service log on
user for the MSSQLServer logon. I wouldn't expect this to make any differenc
e
in her ability to insert a record into this table. Am I wrong?
Any help would be greatly appreciated.Hi,
By any chance some one DENY INSERT to this user for this table.
Thanks
Hari
SQL Server MVP
"Snowmizer" <Snowmizer@.discussions.microsoft.com> wrote in message
news:104EB25F-C2F7-46A3-8A5B-7B9AC61A6F16@.microsoft.com...
>I have a user trying to insert a record into a table on my SQL 2000 server.
> When she tries to do the insert she gets a message "Insert permissions
> denied
> on object 'mytable', database 'mydatabase', owner 'dbo'". This user is a
> member of an Active Directory group on my network. The AD group has rights
> to
> the database on my SQL Server. The AD group has select, insert, update and
> delete rights to the table in question. Yet even after all of this she is
> still unable to insert records into this table.
> What could be causing my problem? We recently changed the service log on
> user for the MSSQLServer logon. I wouldn't expect this to make any
> difference
> in her ability to insert a record into this table. Am I wrong?
> Any help would be greatly appreciated.
>

permission denied

iam working with http location and using sql server 2005 its getting an error as "INSERT permission denied on object CourseDetails, database 'mydb', schema 'dbo'." "CourseDetails" is my table name "mydb" is database name i worked same project with filesystem location ,there it is working

This is almost certainly being caused because the account that is running the web site (ASPNET or NETWORK SERVICE, depending on which version of IIS you're running) is not allowed permission to access the SQL Server database. Note that for a file based application, running under the development web server, your user account will have been used.

Check the connection string that is being used in the web site. If it is using integrated security (likely), then you will need to ensure that the ASPNET or NETWORK SERVICE account (or, more precisely, the account that is being used to run the web site) is allowed access to the database.