显示标签为“users”的博文。显示所有博文
显示标签为“users”的博文。显示所有博文

2012年3月19日星期一

FK Naming

Hello,

I have 2 tables: Articles and Users.
These 2 tables are related by AuthorId (FK) in Articles and UserId (PK) in Users.

My question is: should the use the same name for the 2 keys, i.e., UserId?

Or it is normal to use AuthorId in Articles table and UserId in Users table. This makes more sense.

Just a naming question.

Thanks,
Miguel

It's normal to use AuthorID. Actually this would make it more clear (for anyone else looking at your database) that users from the Users table are the authors of these articles.

So, if you ever created for instance a ReaderComment table, you can have a ReaderID FK that is also a reference to the Users table.

Good Luck :)

|||

If you want to make it cleat that this is an Author and is also an FK from the Users table, you can name it something like ' Author_UserID_FK "

|||

Answer is May be or may not be

As per the general norms in paent and child tables if columns names are same there will be no confusion.

Thank u

Baba

Please remember to click "Mark as Answer" on this post if it helped you.

|||

Ania:

If you want to make it cleat that this is an Author and is also an FK from the Users table, you can name it something like ' Author_UserID_FK "

It's all about what flavor you prefer. Personally, I try to avoid involving prefixing/suffixing columns for PKs and FKs. I mean, if you were ever curious if it is an FK or not, have a look in the table definition. Making complex column names like this will only make your SQL code harder to read and debug.

My suggestion: Keep names simple and intuitive. Don't use names for expressing relations. The DDL is perfectly capable of doing this already.

(Besides, you have no guarantee that a column named FK is actually an FK...)

|||

I typically name the foreign key like this:

<child_table_name>_<parent_table_name>_fk.

If there are more than one, I name it like this:

<child_table_name>_<parent_table_name>_author_fk.

<child_table_name>_<parent_table_name>_reader_fk.

As for the foreign key column names themselves, I typically use this method:

UserIdAuthor

UserIdReader

It's a bit more typing than AuthorId and ReaderId, but, at a glance, you know both it's fk lineage and its business purpose.

PS. I don't put the fk column name in the fk name because there may be more than one column in the fk!

fixing SQL CE Merge replication

Does anyone know of a way to regenerate the system tables that merge
replication uses? A lot of my users are getting blank system tables which
causes native exceptions when I go to sync or reinitialize. The number of
rows that I would stand to lose if I couldn't regenerate these tables is
really unacceptable. On a side note, how are these tables clearing
themselves? Our program doesn't touch any system tables and the db is
password protected to keep users out of it.
Currently, we are creating a new subscription and then inserting the rows
that are in the old database into the new db. The problem with this is that
it takes over an hour per database.
Something is very wrong here. Your merge replication system tables should
have data in them. Especially msmerge_contents, and msmerge_replinfo.
You should call PSS on this one.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
"Scott Simons" <Scott.Simons.At.MealMagic.Com.Remove.This> wrote in message
news:8D20ADAA-6607-4AEB-A2FE-AF7E2A33DD93@.microsoft.com...
> Does anyone know of a way to regenerate the system tables that merge
> replication uses? A lot of my users are getting blank system tables which
> causes native exceptions when I go to sync or reinitialize. The number of
> rows that I would stand to lose if I couldn't regenerate these tables is
> really unacceptable. On a side note, how are these tables clearing
> themselves? Our program doesn't touch any system tables and the db is
> password protected to keep users out of it.
> Currently, we are creating a new subscription and then inserting the rows
> that are in the old database into the new db. The problem with this is
that
> it takes over an hour per database.

fixing orphan users

Hi All,
I'm trying to fix all the orphans users for all the databases in my sql
server 2000 using the code above, but I'm getting an error that the second
cursor already exist.
Can I do a cursor inside another one?
How can I fix this problem?
Any ideas?
Tks in advance
JFB
DECLARE @.DBName sysname
,@.DBStatus int
,@.dbid int
,@.TempDBName nvarchar(70)
SELECT @.DBName = '*'
SELECT @.TempDBName = ' '
DECLARE DBs CURSOR FOR
SELECT name, dbid, status, name
FROM master..sysdatabases
WHERE [name] <> 'tempdb'
and [name] <> 'master'
and [name] <> 'model'
FOR READ ONLY
OPEN DBs
FETCH NEXT FROM DBs INTO @.DBName, @.dbid, @.DBStatus, @.TempDBName
WHILE @.@.FETCH_STATUS = 0
BEGIN
Print @.TempDBName
DECLARE @.tempString nvarchar(255)
SELECT @.tempString = 'USE ' + @.TempDBName +'
DECLARE @.UserName nvarchar(50)
DECLARE orphanuser_cur cursor for
SELECT UserName = name
FROM sysusers
WHERE issqluser = 1 and (sid is not null and sid <> 0x0) and
suser_sname(sid) is null
ORDER BY name
OPEN orphanuser_cur
FETCH NEXT FROM orphanuser_cur INTO @.UserName
WHILE (@.@.fetch_status = 0)
BEGIN
PRINT @.UserName '' user name being resynced''
EXEC sp_change_users_login ''Update_one'', @.UserName, @.UserName
FETCH NEXT FROM orphanuser_cur INTO @.UserName
END
CLOSE orphanuser_cur
DEALLOCATE orphanuser_cur'
EXEC (@.tempString)
FETCH NEXT FROM DBs INTO @.DBName, @.dbid, @.DBStatus, @.TempDBName
END
CLOSE DBs
DEALLOCATE DBsOn Wed, 16 Feb 2005 18:06:32 -0500, JFB wrote:

>I'm trying to fix all the orphans users for all the databases in my sql
>server 2000 using the code above, but I'm getting an error that the second
>cursor already exist.
>Can I do a cursor inside another one?
>How can I fix this problem?
>Any ideas?
Hi JFB,
The first thing to do when troubleshooting dynamic SQL is to change
EXEC (@.tempString)
to
PRINT @.tempString
and inspect the results.
If you do that, you'll instantly note that the length of your dynamic SQL
exceeds the 255 character you used in the declaration of @.tempString.
Another problem you'll find after fixing this one is here:
> PRINT @.UserName '' user name being resynced''
This should be changed to
PRINT @.UserName + '' user name being resynced''
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Yes Hugo, Tks for you reply and help.
I got those problems...
Rgds
JFB
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:f8v9115l8464ppt54s56bo45knisli5l3u@.
4ax.com...
> On Wed, 16 Feb 2005 18:06:32 -0500, JFB wrote:
>
> Hi JFB,
> The first thing to do when troubleshooting dynamic SQL is to change
> EXEC (@.tempString)
> to
> PRINT @.tempString
> and inspect the results.
> If you do that, you'll instantly note that the length of your dynamic SQL
> exceeds the 255 character you used in the declaration of @.tempString.
> Another problem you'll find after fixing this one is here:
> This should be changed to
> PRINT @.UserName + '' user name being resynced''
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)|||Yes Hugo, Tks for you reply and help.
I got those problems...
Rgds
JFB
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:f8v9115l8464ppt54s56bo45knisli5l3u@.
4ax.com...
> On Wed, 16 Feb 2005 18:06:32 -0500, JFB wrote:
>
> Hi JFB,
> The first thing to do when troubleshooting dynamic SQL is to change
> EXEC (@.tempString)
> to
> PRINT @.tempString
> and inspect the results.
> If you do that, you'll instantly note that the length of your dynamic SQL
> exceeds the 255 character you used in the declaration of @.tempString.
> Another problem you'll find after fixing this one is here:
> This should be changed to
> PRINT @.UserName + '' user name being resynced''
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)

2012年3月11日星期日

Fixed header rowin Reporting Services

Hi,
I've been devloping reports using Reporting Services. It's useful and fast.
However, I've this group of users who would like to fix the header row while
the data is able to scoll down and up without moving the header row. Is
there any configuration that can solve my problem? Below is a simple
illustration, hope anyone can help me in this.
| X header | Y header | Z header | ... | => This row must be fixed
| X data1 | Y data1 | Z data1 |... | ^
| X data2 | Y data2 | Z data2 |... | |
| X data3 | Y data3 | Z data3 |... | |
| X data4 | Y data4 | Z data4 |... | | These data rows
should be able to
| X data5 | Y data5 | Z data5 |... | | scroll up and down
| ........ | ........ | ........ |... | |
| X dataN | Y dataN | Z dataN |... | v
Best Regards,
Samie
I don't know how to do this.
I suspect that you will have a better response within the Reporting Services
newsgroup. I am including that group in this reply. Hopefully someone in
that group will be able to help.
Keith
"Samie" <Samie@.discussions.microsoft.com> wrote in message
news:D12C8438-E59D-49D5-9E2D-31C4D3A6B17C@.microsoft.com...
> Hi,
> I've been devloping reports using Reporting Services. It's useful and
fast.
> However, I've this group of users who would like to fix the header row
while
> the data is able to scoll down and up without moving the header row. Is
> there any configuration that can solve my problem? Below is a simple
> illustration, hope anyone can help me in this.
> | X header | Y header | Z header | ... | => This row must be fixed
> | X data1 | Y data1 | Z data1 |... | ^
> | X data2 | Y data2 | Z data2 |... | |
> | X data3 | Y data3 | Z data3 |... | |
> | X data4 | Y data4 | Z data4 |... | | These data rows
> should be able to
> | X data5 | Y data5 | Z data5 |... | | scroll up and down
> | ........ | ........ | ........ |... | |
> | X dataN | Y dataN | Z dataN |... | v
>
> Best Regards,
> Samie
>
|||Thanks Keith...
I'm hoping someone can help me too.
Regards,
samie
"Keith Kratochvil" wrote:

> I don't know how to do this.
> I suspect that you will have a better response within the Reporting Services
> newsgroup. I am including that group in this reply. Hopefully someone in
> that group will be able to help.
> --
> Keith
>
> "Samie" <Samie@.discussions.microsoft.com> wrote in message
> news:D12C8438-E59D-49D5-9E2D-31C4D3A6B17C@.microsoft.com...
> fast.
> while
>
|||Samie,
Fixed headers are not supported with version 1.0 but on the wish list for
2005.
Hope this helps.
Teo Lachev, MVP [SQL Server], MCSD, MCT
Author: "Microsoft Reporting Services in Action"
Publisher website: http://www.manning.com/lachev
Buy it from Amazon.com: http://shrinkster.com/eq
Home page and blog: http://www.prologika.com/
"Samie" <Samie@.discussions.microsoft.com> wrote in message
news:119F060E-C479-4AF6-97E2-B59600B8D383@.microsoft.com...[vbcol=seagreen]
> Thanks Keith...
> I'm hoping someone can help me too.
> Regards,
> samie
>
> "Keith Kratochvil" wrote:
Services[vbcol=seagreen]
in[vbcol=seagreen]
row[vbcol=seagreen]
Is[vbcol=seagreen]
fixed[vbcol=seagreen]
rows[vbcol=seagreen]
down[vbcol=seagreen]

Fixed header

Hello!

I have a report that the users reach from an url. In the url I have rc:parameters = false. That part works fine. But when I use rc:parameters = false, the property fixed header doesn't seem to work. If I run the report from the report server it works fine, but not from the url.

Any ideas?

/C

Fixed headers don't work if the url access displays more than one page at the same time. The best way to ensure that fixed headers work is to run with rc:toolbar=true|||

Ok, I see...
I tried with "rc:toolbar=true" and set all parameters to "hidden" instead. It works fine, even though it feels a little bit slower when the report is rendering.
Another problem I faced before when I had rc:Parameters = false was that when I did a user sort on any column, the ability to go to next page was gone.
Before the user sort, I could scroll down to next page but when I sorted a column, I could only scroll the first page.
Is it a bug?

Fixed Database Roles vs Application Roles

After reading Books Online, I am still confused with Database Role vs Application role.

My intention is to control the end users' authority on the database, where the end users will access through Winforms client application. With proper assignment of schema and database roles to an user, I believe this will enough to control the permisison of an user.

If this is the case, why Application role exists? When and why should I use Application Role? How is it different from Fixed Database Role?

Application roles prevent users from having direct permission on the database, and force them to access it via the application. If you grant permission to the users directly, then if you have lots of users, you will have lots of permissions to maintain. Further, with direct permissions, the user could start accessing the database through interfaces such as Microsoft Access which you may not want them to do.

Typically, application roles are used by applications that perform their own user authentication.

Hope this helps.

|||So, if I want users to access business data ONLY from my client application, I should use application roles. However, if I use application roles, does it mean that I don't have to assign any database role to an user? i.e. can I rely totally on application roles plus schema? Besides, what is the best practise to store the password of application roles in my application?|||

Yes. That's correct. If you use application roles, you just assign permissions to that app role. The application then activates it on connection. You don't need to do anything with user permissions.

As far as the password goes, one approach is to store the password encrypted in the registry on the application server. The application decrypts it before calling the setapprole procedure. This allows you to avoid storing the password in application code and allows you to change the password as well without having to recompile the app.

|||

Great questions. I'm new to AppRoles and am looking a good, simple example, showing how to use them, including the necessary setup on sql 2005 to make it all work. Anyone have a suggested link?

TIA,

barkingdog

P.S. BOL is accurate but too fragmented to be useful to a begineer. After I understand how do to something, then I usually appreciate what BOL is saying.

|||

Question:

Why use an application role over using a SQL User account for the application?

thanks,

Nate

|||

You can actually use a SQL account as well, but in previous versions of SQL Server the impersonation features were not as rich as they are in SQL Server 2005, so application roles used to be the only available way. Now you could as well perform an EXECUTE AS with NO REVERT and that would pretty much achieve what you get from using an application role. Also see the CREATE USER WITHOUT LOGIN statement for creating a principal that is sand-boxed to a database.

Raul also wrote an interesting post on users without login, which you might find useful: http://blogs.msdn.com/raulga/archive/2006/07/03/655587.aspx.

Thanks
Laurentiu

|||

This is great! thank you for the information.

Now my final question!

I have an application in which I want the SQL Profiler will see which user is executing what stored procedure or query, but those queries or stored procedures should only be executed from my application, and fail if they try to execute the query from another database app (some of my users have Query Analyzer)

AKA an application should be able to execute the stored procedure as the Logged in user (windows authentication), but if the same user using windows authentication connects to the same database using another application, like query analyzer, they will be denied. So when my DBA looks into the database, they can see in the application field in Query Profiler that Jimmy is executing sp_GetData from "Application1" (I have specified this in the connection string) but Paul is getting denied from executing sp_GetData from the "Query Analyzer" application.

Thanks for your help,

Nate

|||

This is currently not possible, as there is no mechanism available for authenticating applications.

Thanks

Laurentiu

|||I upgraded a db from SQL Server 2000 sp4 to SQL Server 2005 sp2. I've got a legacy app that had an application role associated with it. When I upgraded my db and attempted to launch my application, only one of my log-ins works. It's ironic because that login is not special. It isn't sysadmin or anything like that. In this old app, all the logins required dbo rights to the database and the app itself stuck them into the application role. I tried deleting and recreating my users and that didn't help. I tried a new user and that didn't help either. The application role converted but it isn't associated with a valid schema. (The default schema assigned to it doesn't exist.) Is it possible for an application role to become orphaned? I had problems with a few orphaned users when i was moving my databases over for testing, but I followed microsoft's instructions for dealing with orphaned users and it worked great. I'm stumped.|||

Application roles shouldn’t become orphaned. The root cause of the orphaned users is that the associated SID is invalid after restoring the DB on a different server (because the corresponding login doesn’t exist on the new server).Application roles have a SID, but it is not linked to master DB (or to any other DB), and it is possible to set a default schema on them as well (you can use ALTER APPLICATION ROLE syntax to change the default schema).

It may be possible that the application has a different case for the password, in SQL Server 2005 passwords are case sensitive. If this is the case, try resetting the password using ALTER APPLCIATION ROLE.

http://msdn2.microsoft.com/en-us/library/ms188900.aspx

I hope this information helps,

-Raul Garcia

SDE/T

SQL Server Engine

|||

The password for this application role is actually generated in script. See below. That default schema (xyz_user) doesn't exist when I look in SSMS. When I right-click on the application role and select properties, it shows the password as ****'s for security. What's strange is that it says the schemas owned by this role are "db_owner" and "xyz_user." Yet, when I expand the schemas folder, xyz_user isn't there. I tried creating it again, but that didn't help.

/****** Object: ApplicationRole [xyz_user] Script Date: 07/25/2007 13:51:07 ******/

/* To avoid disclosure of passwords, the password is generated in script. */

declare @.idx as int

declare @.randomPwd as nvarchar(64)

declare @.rnd as float

select @.idx = 0

select @.randomPwd = N''

select @.rnd = rand((@.@.CPU_BUSY % 100) + ((@.@.IDLE % 100) * 100) +

(DATEPART(ss, GETDATE()) * 10000) + ((cast(DATEPART(ms, GETDATE()) as int) % 100) * 1000000))

while @.idx < 64

begin

select @.randomPwd = @.randomPwd + char((cast((@.rnd * 83) as int) + 43))

select @.idx = @.idx + 1

select @.rnd = rand()

end

declare @.statement nvarchar(4000)

select @.statement = N'CREATE APPLICATION ROLE [xyz_user] WITH DEFAULT_SCHEMA = [xyz_user], ' + N'PASSWORD = N' + QUOTENAME(@.randomPwd,'''')

EXEC dbo.sp_executesql @.statement

|||

That is indeed very strange. Can you try to repro it on a new (i.e. test) DB? I am suspecting there is something in the database that is affecting your results.

I tried on SQL Server 2005 Sp2, and I got no schemas owned by [user_xyz] (as expected), and no schema named [user_xyz] (again as expected).

Thanks,

-Raul Garcia

SDE/T

SQL Server Engine

Fixed Database Roles vs Application Roles

After reading Books Online, I am still confused with Database Role vs Application role.

My intention is to control the end users' authority on the database, where the end users will access through Winforms client application. With proper assignment of schema and database roles to an user, I believe this will enough to control the permisison of an user.

If this is the case, why Application role exists? When and why should I use Application Role? How is it different from Fixed Database Role?

Application roles prevent users from having direct permission on the database, and force them to access it via the application. If you grant permission to the users directly, then if you have lots of users, you will have lots of permissions to maintain. Further, with direct permissions, the user could start accessing the database through interfaces such as Microsoft Access which you may not want them to do.

Typically, application roles are used by applications that perform their own user authentication.

Hope this helps.

|||So, if I want users to access business data ONLY from my client application, I should use application roles. However, if I use application roles, does it mean that I don't have to assign any database role to an user? i.e. can I rely totally on application roles plus schema? Besides, what is the best practise to store the password of application roles in my application?|||

Yes. That's correct. If you use application roles, you just assign permissions to that app role. The application then activates it on connection. You don't need to do anything with user permissions.

As far as the password goes, one approach is to store the password encrypted in the registry on the application server. The application decrypts it before calling the setapprole procedure. This allows you to avoid storing the password in application code and allows you to change the password as well without having to recompile the app.

|||

Great questions. I'm new to AppRoles and am looking a good, simple example, showing how to use them, including the necessary setup on sql 2005 to make it all work. Anyone have a suggested link?

TIA,

barkingdog

P.S. BOL is accurate but too fragmented to be useful to a begineer. After I understand how do to something, then I usually appreciate what BOL is saying.

|||

Question:

Why use an application role over using a SQL User account for the application?

thanks,

Nate

|||

You can actually use a SQL account as well, but in previous versions of SQL Server the impersonation features were not as rich as they are in SQL Server 2005, so application roles used to be the only available way. Now you could as well perform an EXECUTE AS with NO REVERT and that would pretty much achieve what you get from using an application role. Also see the CREATE USER WITHOUT LOGIN statement for creating a principal that is sand-boxed to a database.

Raul also wrote an interesting post on users without login, which you might find useful: http://blogs.msdn.com/raulga/archive/2006/07/03/655587.aspx.

Thanks
Laurentiu

|||

This is great! thank you for the information.

Now my final question!

I have an application in which I want the SQL Profiler will see which user is executing what stored procedure or query, but those queries or stored procedures should only be executed from my application, and fail if they try to execute the query from another database app (some of my users have Query Analyzer)

AKA an application should be able to execute the stored procedure as the Logged in user (windows authentication), but if the same user using windows authentication connects to the same database using another application, like query analyzer, they will be denied. So when my DBA looks into the database, they can see in the application field in Query Profiler that Jimmy is executing sp_GetData from "Application1" (I have specified this in the connection string) but Paul is getting denied from executing sp_GetData from the "Query Analyzer" application.

Thanks for your help,

Nate

|||

This is currently not possible, as there is no mechanism available for authenticating applications.

Thanks

Laurentiu

|||I upgraded a db from SQL Server 2000 sp4 to SQL Server 2005 sp2. I've got a legacy app that had an application role associated with it. When I upgraded my db and attempted to launch my application, only one of my log-ins works. It's ironic because that login is not special. It isn't sysadmin or anything like that. In this old app, all the logins required dbo rights to the database and the app itself stuck them into the application role. I tried deleting and recreating my users and that didn't help. I tried a new user and that didn't help either. The application role converted but it isn't associated with a valid schema. (The default schema assigned to it doesn't exist.) Is it possible for an application role to become orphaned? I had problems with a few orphaned users when i was moving my databases over for testing, but I followed microsoft's instructions for dealing with orphaned users and it worked great. I'm stumped.|||

Application roles shouldn’t become orphaned. The root cause of the orphaned users is that the associated SID is invalid after restoring the DB on a different server (because the corresponding login doesn’t exist on the new server).Application roles have a SID, but it is not linked to master DB (or to any other DB), and it is possible to set a default schema on them as well (you can use ALTER APPLICATION ROLE syntax to change the default schema).

It may be possible that the application has a different case for the password, in SQL Server 2005 passwords are case sensitive. If this is the case, try resetting the password using ALTER APPLCIATION ROLE.

http://msdn2.microsoft.com/en-us/library/ms188900.aspx

I hope this information helps,

-Raul Garcia

SDE/T

SQL Server Engine

|||

The password for this application role is actually generated in script. See below. That default schema (xyz_user) doesn't exist when I look in SSMS. When I right-click on the application role and select properties, it shows the password as ****'s for security. What's strange is that it says the schemas owned by this role are "db_owner" and "xyz_user." Yet, when I expand the schemas folder, xyz_user isn't there. I tried creating it again, but that didn't help.

/****** Object: ApplicationRole [xyz_user] Script Date: 07/25/2007 13:51:07 ******/

/* To avoid disclosure of passwords, the password is generated in script. */

declare @.idx as int

declare @.randomPwd as nvarchar(64)

declare @.rnd as float

select @.idx = 0

select @.randomPwd = N''

select @.rnd = rand((@.@.CPU_BUSY % 100) + ((@.@.IDLE % 100) * 100) +

(DATEPART(ss, GETDATE()) * 10000) + ((cast(DATEPART(ms, GETDATE()) as int) % 100) * 1000000))

while @.idx < 64

begin

select @.randomPwd = @.randomPwd + char((cast((@.rnd * 83) as int) + 43))

select @.idx = @.idx + 1

select @.rnd = rand()

end

declare @.statement nvarchar(4000)

select @.statement = N'CREATE APPLICATION ROLE [xyz_user] WITH DEFAULT_SCHEMA = [xyz_user], ' + N'PASSWORD = N' + QUOTENAME(@.randomPwd,'''')

EXEC dbo.sp_executesql @.statement

|||

That is indeed very strange. Can you try to repro it on a new (i.e. test) DB? I am suspecting there is something in the database that is affecting your results.

I tried on SQL Server 2005 Sp2, and I got no schemas owned by [user_xyz] (as expected), and no schema named [user_xyz] (again as expected).

Thanks,

-Raul Garcia

SDE/T

SQL Server Engine

Fixed Database Roles vs Application Roles

After reading Books Online, I am still confused with Database Role vs Application role.

My intention is to control the end users' authority on the database, where the end users will access through Winforms client application. With proper assignment of schema and database roles to an user, I believe this will enough to control the permisison of an user.

If this is the case, why Application role exists? When and why should I use Application Role? How is it different from Fixed Database Role?

Application roles prevent users from having direct permission on the database, and force them to access it via the application. If you grant permission to the users directly, then if you have lots of users, you will have lots of permissions to maintain. Further, with direct permissions, the user could start accessing the database through interfaces such as Microsoft Access which you may not want them to do.

Typically, application roles are used by applications that perform their own user authentication.

Hope this helps.

|||So, if I want users to access business data ONLY from my client application, I should use application roles. However, if I use application roles, does it mean that I don't have to assign any database role to an user? i.e. can I rely totally on application roles plus schema? Besides, what is the best practise to store the password of application roles in my application?
|||

Yes. That's correct. If you use application roles, you just assign permissions to that app role. The application then activates it on connection. You don't need to do anything with user permissions.

As far as the password goes, one approach is to store the password encrypted in the registry on the application server. The application decrypts it before calling the setapprole procedure. This allows you to avoid storing the password in application code and allows you to change the password as well without having to recompile the app.

|||

Great questions. I'm new to AppRoles and am looking a good, simple example, showing how to use them, including the necessary setup on sql 2005 to make it all work. Anyone have a suggested link?

TIA,

barkingdog

P.S. BOL is accurate but too fragmented to be useful to a begineer. After I understand how do to something, then I usually appreciate what BOL is saying.

|||

Question:

Why use an application role over using a SQL User account for the application?

thanks,

Nate

|||

You can actually use a SQL account as well, but in previous versions of SQL Server the impersonation features were not as rich as they are in SQL Server 2005, so application roles used to be the only available way. Now you could as well perform an EXECUTE AS with NO REVERT and that would pretty much achieve what you get from using an application role. Also see the CREATE USER WITHOUT LOGIN statement for creating a principal that is sand-boxed to a database.

Raul also wrote an interesting post on users without login, which you might find useful: http://blogs.msdn.com/raulga/archive/2006/07/03/655587.aspx.

Thanks
Laurentiu

|||

This is great! thank you for the information.

Now my final question!

I have an application in which I want the SQL Profiler will see which user is executing what stored procedure or query, but those queries or stored procedures should only be executed from my application, and fail if they try to execute the query from another database app (some of my users have Query Analyzer)

AKA an application should be able to execute the stored procedure as the Logged in user (windows authentication), but if the same user using windows authentication connects to the same database using another application, like query analyzer, they will be denied. So when my DBA looks into the database, they can see in the application field in Query Profiler that Jimmy is executing sp_GetData from "Application1" (I have specified this in the connection string) but Paul is getting denied from executing sp_GetData from the "Query Analyzer" application.

Thanks for your help,

Nate

|||

This is currently not possible, as there is no mechanism available for authenticating applications.

Thanks

Laurentiu

|||I upgraded a db from SQL Server 2000 sp4 to SQL Server 2005 sp2. I've got a legacy app that had an application role associated with it. When I upgraded my db and attempted to launch my application, only one of my log-ins works. It's ironic because that login is not special. It isn't sysadmin or anything like that. In this old app, all the logins required dbo rights to the database and the app itself stuck them into the application role. I tried deleting and recreating my users and that didn't help. I tried a new user and that didn't help either. The application role converted but it isn't associated with a valid schema. (The default schema assigned to it doesn't exist.) Is it possible for an application role to become orphaned? I had problems with a few orphaned users when i was moving my databases over for testing, but I followed microsoft's instructions for dealing with orphaned users and it worked great. I'm stumped.|||

Application roles shouldn’t become orphaned. The root cause of the orphaned users is that the associated SID is invalid after restoring the DB on a different server (because the corresponding login doesn’t exist on the new server).Application roles have a SID, but it is not linked to master DB (or to any other DB), and it is possible to set a default schema on them as well (you can use ALTER APPLICATION ROLE syntax to change the default schema).

It may be possible that the application has a different case for the password, in SQL Server 2005 passwords are case sensitive. If this is the case, try resetting the password using ALTER APPLCIATION ROLE.

http://msdn2.microsoft.com/en-us/library/ms188900.aspx

I hope this information helps,

-Raul Garcia

SDE/T

SQL Server Engine

|||

The password for this application role is actually generated in script. See below. That default schema (xyz_user) doesn't exist when I look in SSMS. When I right-click on the application role and select properties, it shows the password as ****'s for security. What's strange is that it says the schemas owned by this role are "db_owner" and "xyz_user." Yet, when I expand the schemas folder, xyz_user isn't there. I tried creating it again, but that didn't help.

/****** Object: ApplicationRole [xyz_user] Script Date: 07/25/2007 13:51:07 ******/

/* To avoid disclosure of passwords, the password is generated in script. */

declare @.idx as int

declare @.randomPwd as nvarchar(64)

declare @.rnd as float

select @.idx = 0

select @.randomPwd = N''

select @.rnd = rand((@.@.CPU_BUSY % 100) + ((@.@.IDLE % 100) * 100) +

(DATEPART(ss, GETDATE()) * 10000) + ((cast(DATEPART(ms, GETDATE()) as int) % 100) * 1000000))

while @.idx < 64

begin

select @.randomPwd = @.randomPwd + char((cast((@.rnd * 83) as int) + 43))

select @.idx = @.idx + 1

select @.rnd = rand()

end

declare @.statement nvarchar(4000)

select @.statement = N'CREATE APPLICATION ROLE [xyz_user] WITH DEFAULT_SCHEMA = [xyz_user], ' + N'PASSWORD = N' + QUOTENAME(@.randomPwd,'''')

EXEC dbo.sp_executesql @.statement

|||

That is indeed very strange. Can you try to repro it on a new (i.e. test) DB? I am suspecting there is something in the database that is affecting your results.

I tried on SQL Server 2005 Sp2, and I got no schemas owned by [user_xyz] (as expected), and no schema named [user_xyz] (again as expected).

Thanks,

-Raul Garcia

SDE/T

SQL Server Engine

Fixed Database Roles vs Application Roles

After reading Books Online, I am still confused with Database Role vs Application role.

My intention is to control the end users' authority on the database, where the end users will access through Winforms client application. With proper assignment of schema and database roles to an user, I believe this will enough to control the permisison of an user.

If this is the case, why Application role exists? When and why should I use Application Role? How is it different from Fixed Database Role?

Application roles prevent users from having direct permission on the database, and force them to access it via the application. If you grant permission to the users directly, then if you have lots of users, you will have lots of permissions to maintain. Further, with direct permissions, the user could start accessing the database through interfaces such as Microsoft Access which you may not want them to do.

Typically, application roles are used by applications that perform their own user authentication.

Hope this helps.

|||So, if I want users to access business data ONLY from my client application, I should use application roles. However, if I use application roles, does it mean that I don't have to assign any database role to an user? i.e. can I rely totally on application roles plus schema? Besides, what is the best practise to store the password of application roles in my application?
|||

Yes. That's correct. If you use application roles, you just assign permissions to that app role. The application then activates it on connection. You don't need to do anything with user permissions.

As far as the password goes, one approach is to store the password encrypted in the registry on the application server. The application decrypts it before calling the setapprole procedure. This allows you to avoid storing the password in application code and allows you to change the password as well without having to recompile the app.

|||

Great questions. I'm new to AppRoles and am looking a good, simple example, showing how to use them, including the necessary setup on sql 2005 to make it all work. Anyone have a suggested link?

TIA,

barkingdog

P.S. BOL is accurate but too fragmented to be useful to a begineer. After I understand how do to something, then I usually appreciate what BOL is saying.

|||

Question:

Why use an application role over using a SQL User account for the application?

thanks,

Nate

|||

You can actually use a SQL account as well, but in previous versions of SQL Server the impersonation features were not as rich as they are in SQL Server 2005, so application roles used to be the only available way. Now you could as well perform an EXECUTE AS with NO REVERT and that would pretty much achieve what you get from using an application role. Also see the CREATE USER WITHOUT LOGIN statement for creating a principal that is sand-boxed to a database.

Raul also wrote an interesting post on users without login, which you might find useful: http://blogs.msdn.com/raulga/archive/2006/07/03/655587.aspx.

Thanks
Laurentiu

|||

This is great! thank you for the information.

Now my final question!

I have an application in which I want the SQL Profiler will see which user is executing what stored procedure or query, but those queries or stored procedures should only be executed from my application, and fail if they try to execute the query from another database app (some of my users have Query Analyzer)

AKA an application should be able to execute the stored procedure as the Logged in user (windows authentication), but if the same user using windows authentication connects to the same database using another application, like query analyzer, they will be denied. So when my DBA looks into the database, they can see in the application field in Query Profiler that Jimmy is executing sp_GetData from "Application1" (I have specified this in the connection string) but Paul is getting denied from executing sp_GetData from the "Query Analyzer" application.

Thanks for your help,

Nate

|||

This is currently not possible, as there is no mechanism available for authenticating applications.

Thanks

Laurentiu

|||I upgraded a db from SQL Server 2000 sp4 to SQL Server 2005 sp2. I've got a legacy app that had an application role associated with it. When I upgraded my db and attempted to launch my application, only one of my log-ins works. It's ironic because that login is not special. It isn't sysadmin or anything like that. In this old app, all the logins required dbo rights to the database and the app itself stuck them into the application role. I tried deleting and recreating my users and that didn't help. I tried a new user and that didn't help either. The application role converted but it isn't associated with a valid schema. (The default schema assigned to it doesn't exist.) Is it possible for an application role to become orphaned? I had problems with a few orphaned users when i was moving my databases over for testing, but I followed microsoft's instructions for dealing with orphaned users and it worked great. I'm stumped.|||

Application roles shouldn’t become orphaned. The root cause of the orphaned users is that the associated SID is invalid after restoring the DB on a different server (because the corresponding login doesn’t exist on the new server).Application roles have a SID, but it is not linked to master DB (or to any other DB), and it is possible to set a default schema on them as well (you can use ALTER APPLICATION ROLE syntax to change the default schema).

It may be possible that the application has a different case for the password, in SQL Server 2005 passwords are case sensitive. If this is the case, try resetting the password using ALTER APPLCIATION ROLE.

http://msdn2.microsoft.com/en-us/library/ms188900.aspx

I hope this information helps,

-Raul Garcia

SDE/T

SQL Server Engine

|||

The password for this application role is actually generated in script. See below. That default schema (xyz_user) doesn't exist when I look in SSMS. When I right-click on the application role and select properties, it shows the password as ****'s for security. What's strange is that it says the schemas owned by this role are "db_owner" and "xyz_user." Yet, when I expand the schemas folder, xyz_user isn't there. I tried creating it again, but that didn't help.

/****** Object: ApplicationRole [xyz_user] Script Date: 07/25/2007 13:51:07 ******/

/* To avoid disclosure of passwords, the password is generated in script. */

declare @.idx as int

declare @.randomPwd as nvarchar(64)

declare @.rnd as float

select @.idx = 0

select @.randomPwd = N''

select @.rnd = rand((@.@.CPU_BUSY % 100) + ((@.@.IDLE % 100) * 100) +

(DATEPART(ss, GETDATE()) * 10000) + ((cast(DATEPART(ms, GETDATE()) as int) % 100) * 1000000))

while @.idx < 64

begin

select @.randomPwd = @.randomPwd + char((cast((@.rnd * 83) as int) + 43))

select @.idx = @.idx + 1

select @.rnd = rand()

end

declare @.statement nvarchar(4000)

select @.statement = N'CREATE APPLICATION ROLE [xyz_user] WITH DEFAULT_SCHEMA = [xyz_user], ' + N'PASSWORD = N' + QUOTENAME(@.randomPwd,'''')

EXEC dbo.sp_executesql @.statement

|||

That is indeed very strange. Can you try to repro it on a new (i.e. test) DB? I am suspecting there is something in the database that is affecting your results.

I tried on SQL Server 2005 Sp2, and I got no schemas owned by [user_xyz] (as expected), and no schema named [user_xyz] (again as expected).

Thanks,

-Raul Garcia

SDE/T

SQL Server Engine

Fixed Column Headers

I have a report in Reporting Services that I want the users to be able to
scroll up and down with the column headers fixed, just like freezing a window
in Excel. I'd like to have the far left remain fixed as well, but that's not
as important as the headers. Does anyone know how to do that?This feature is not in RS 2000, but will be supported in the next release.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jim" <Jim@.discussions.microsoft.com> wrote in message
news:E161DB2B-5739-4816-B1BF-0222C3E51C79@.microsoft.com...
>I have a report in Reporting Services that I want the users to be able to
> scroll up and down with the column headers fixed, just like freezing a
> window
> in Excel. I'd like to have the far left remain fixed as well, but that's
> not
> as important as the headers. Does anyone know how to do that?

2012年2月19日星期日

Firefox browser support

Hi all,
We are trying to use SQL RS 2005 at our Company. We have a mix of MAC and
Windows users and I am trying to see whether RS 2005 can work with FireFox. I
created a simple matrix report and the rendering is quite bad, fields dont
have the right widths (IE shows correctly).
How do I get the matrix reports to show correctly in Firefox? Even if it is
extra code that needs to be written somewhere, thats fine. I just want to
have an idea of where to write the code (to show right widths for fields) and
how to implement the code? Any suggestions?
I know the firefox support for RS 2005 has become a FAQ, but I would like to
explore the work-arounds that can be done.
ThanksSeventhSense wrote:
> Hi all,
> We are trying to use SQL RS 2005 at our Company. We have a mix of MAC and
> Windows users and I am trying to see whether RS 2005 can work with FireFox. I
> created a simple matrix report and the rendering is quite bad, fields dont
> have the right widths (IE shows correctly).
> How do I get the matrix reports to show correctly in Firefox? Even if it is
> extra code that needs to be written somewhere, thats fine. I just want to
> have an idea of where to write the code (to show right widths for fields) and
> how to implement the code? Any suggestions?
> I know the firefox support for RS 2005 has become a FAQ, but I would like to
> explore the work-arounds that can be done.
> Thanks
I am having the same problem. I could tell that the data are shown in
firefox, however, it is so tiny that it is not legible, but they show
up nicely in IE.
Any good solution? Thanks.