Showing posts with label users. Show all posts
Showing posts with label users. Show all posts

Wednesday, March 21, 2012

DataRow syntax

command.CommandText = "SELECT UserName from Users WHERE UserID = " = userID

Executing this command returns one table with one column with one row. What is the syntax for getting that value into a variable? I can get the information into a dataSet but I can't get it out. Should I be using a dataSet for this operation?

The rest of the code so far:

SqlDataAdapter dataAdapter =newSqlDataAdapter();

dataAdapter.SelectCommand = command;

dataAdapter.TableMappings.Add("Table","Users");

dataSet =newDataSet();

dataAdapter.Fill(dataSet);

Using that code, your data would be in dataSet.tables[0].rows[0][0].

If that's always just returning one value, you might want to look into using ExecuteScalar instead of the adapter and dataset.

|||

You can just use executeScalar method of SQl command below is example from VB.Net help for scalar modified a little:

Public Function AddProductCategory( _ ByVal UserID As Integer, ByVal connString As String) As Integer Dim Username As string = "" Dim sql As String = "SELECT UserName from Users WHERE UserID = @.USERID" Using conn As New SqlConnection(connString) Dim cmd As New SqlCommand(sql, conn) cmd.Parameters.Add("@.USERID", SqlDbType.Int) cmd.Parameters("@.USERID").Value = newName Try conn.Open() userName = Convert.ToInt32(cmd.ExecuteScalar()) Catch ex As Exception Console.WriteLine(ex.Message) End Try End Using Return newProdIDEnd Function
Thanks
|||

Got it working ... thank you for your help!

Sunday, February 26, 2012

Databases show in EM but not in sysdatabases?

I'm managing the back end SQL 2000 instance for a vendors application. The
application allows users to create databases on the fly for testing, etc.
I opened the instance in Enterprise Manager, and noted that the number of
databases had grown to about a dozen (other than the system databases). Hmm,
so being concerned about drive space, etc, I executed a sp_helpdb.
Yikes..only one of the dozen user databases showed in the listing for
sp_helpdb. Checked sysdatabases and sure enough only one user db shows.
But in EM I can open any of the other 11 DB's, open tables from them, view
options, etc etc. So I'm just curious, how can I view them in EM but they
don't show in sysdatabases?
TIA
<*blush*>..Sigh..one of those days. I did a 'Romo'. Time for a brewski.
"Tibor Karaszi" wrote:

> My guess is that you are connecting to different SQL Server instances.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "bill_the_cat" <billthecat@.discussions.microsoft.com> wrote in message
> news:AF04CEDA-BF16-415C-A652-CB7693F2F16D@.microsoft.com...
>

Databases show in EM but not in sysdatabases?

I'm managing the back end SQL 2000 instance for a vendors application. The
application allows users to create databases on the fly for testing, etc.
I opened the instance in Enterprise Manager, and noted that the number of
databases had grown to about a dozen (other than the system databases). Hmm
,
so being concerned about drive space, etc, I executed a sp_helpdb.
Yikes..only one of the dozen user databases showed in the listing for
sp_helpdb. Checked sysdatabases and sure enough only one user db shows.
But in EM I can open any of the other 11 DB's, open tables from them, view
options, etc etc. So I'm just curious, how can I view them in EM but they
don't show in sysdatabases?
TIAMy guess is that you are connecting to different SQL Server instances.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"bill_the_cat" <billthecat@.discussions.microsoft.com> wrote in message
news:AF04CEDA-BF16-415C-A652-CB7693F2F16D@.microsoft.com...
> I'm managing the back end SQL 2000 instance for a vendors application. Th
e
> application allows users to create databases on the fly for testing, etc.
> I opened the instance in Enterprise Manager, and noted that the number of
> databases had grown to about a dozen (other than the system databases). H
mm,
> so being concerned about drive space, etc, I executed a sp_helpdb.
> Yikes..only one of the dozen user databases showed in the listing for
> sp_helpdb. Checked sysdatabases and sure enough only one user db shows.
> But in EM I can open any of the other 11 DB's, open tables from them, view
> options, etc etc. So I'm just curious, how can I view them in EM but they
> don't show in sysdatabases?
> TIA|||<*blush*>..Sigh..one of those days. I did a 'Romo'. Time for a brewski.
"Tibor Karaszi" wrote:

> My guess is that you are connecting to different SQL Server instances.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "bill_the_cat" <billthecat@.discussions.microsoft.com> wrote in message
> news:AF04CEDA-BF16-415C-A652-CB7693F2F16D@.microsoft.com...
>|||Happens to all of us... :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"bill_the_cat" <billthecat@.discussions.microsoft.com> wrote in message
news:DBD746A2-59BE-49C8-90A9-757086DA9412@.microsoft.com...[vbcol=seagreen]
> <*blush*>..Sigh..one of those days. I did a 'Romo'. Time for a brewski.
> "Tibor Karaszi" wrote:
>

Databases not available through QA for some users


Hey All Gurus,
Why on a large environment with many users, when you attach to QA the
systyem says on a pop up message that several databases are not avail
for viewing. These users are members and logins have the correct
permissions. This happens also when you hit f8 from inside of QA then
the databases do not show in the object browser list? The really wierd
this is you can query these unlisted objects?
does anyone know why this would happen
Bill
*** Sent via Developersdex http://www.examnotes.net ***if the databases are not ready to accept client connection (i.e. still in
recovery phase), they're not accessible.
-oj
"Bill Orova" <nospam@.devdex.com> wrote in message
news:OP4zvC$VFHA.2796@.TK2MSFTNGP09.phx.gbl...
>
> Hey All Gurus,
> Why on a large environment with many users, when you attach to QA the
> systyem says on a pop up message that several databases are not avail
> for viewing. These users are members and logins have the correct
> permissions. This happens also when you hit f8 from inside of QA then
> the databases do not show in the object browser list? The really wierd
> this is you can query these unlisted objects?
> does anyone know why this would happen
> Bill
> *** Sent via Developersdex http://www.examnotes.net ***

Friday, February 17, 2012

Database Users Appear to be Corrupt

We had a hardware error on our production machine and had to replace it with
our backup machine. Both machines are running SQL Server 2000 on Windows
2000. I used the SQL Server database backup file from production to restore
the backup server.
I know about the sid's being out of sync between the logins and the database
users. I used our standard procedures to re-align them but must have done
something wrong. Now when I run sp_change_users_login 'Report', the list is
empty. I can see the users listed under the database using the enterprise
manager and the users can access the database but I fear that some table
somewhere pertaining to users is corrupted.You should be ok. The Report option of
sp_change_users_login only lists logins that are out of
sync. If you don't get any back from
sp_change_users_login 'Report', then they should all be in
sync.
This is taken directly from BOL pertaining to the Report
option:
"Lists the users, and their corresponding security
identifiers (SID), that are in the current database, not
linked to any login."
>--Original Message--
>We had a hardware error on our production machine and had
to replace it with
>our backup machine. Both machines are running SQL Server
2000 on Windows
>2000. I used the SQL Server database backup file from
production to restore
>the backup server.
>I know about the sid's being out of sync between the
logins and the database
>users. I used our standard procedures to re-align them
but must have done
>something wrong. Now when I run
sp_change_users_login 'Report', the list is
>empty. I can see the users listed under the database
using the enterprise
>manager and the users can access the database but I fear
that some table
>somewhere pertaining to users is corrupted.
>
>.
>|||Hi Robert,
Thank you for using MSDN Newsgroup! It's my pleasure to assist you with your issue.
As Van has pointed out, no report from sp_change_ueses_login means no sync problem of
the corresponding SID and everything seems fine on your side.
It is also recommended you try Database Consistency Checker (DBCC) statements after you
backup and restore your database.
You can use DBCC CHECKDB to check the allocation and structural integrity of the whole
database, or use DBCC CHECKALLOC / DBCC CHECKTABLE to check the individual objects
(including some suspicious tables).
For more information, please refer to Books Online on the topic "DBCC CHECKDB" and
"DBCC CHECKTABLE".
Robert, does this answer your question? If there is anything more we can do to assist you,
please feel free to post it in the group
Best regards,
Billy Yao
Microsoft Online Support
----
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only. Thanks.

Database Users and Triggers

I created a trigger on a table T1 for insert and update. The trigger
selects values from table T2, which happens to be in a different
database. It seems I have to create users in that other database for
every user who updates or inserts records into T1. Is there any way
around this, using views or stored procedures, in SQL Server 2000?
Thanks
TimoHi Timo,
I don't think you'll be able to do what you want.
Trigger is running in security context of a user who fired it. As so, select
statement on T2 table is run as that user and user must have proper
permissions.
Danijel Novak
MCP+I, MCSA, MCSE, MCDBA, MCT
"Timo" <timo@.org.org> wrote in message
news:eBj$lRp9FHA.1032@.TK2MSFTNGP11.phx.gbl...
>I created a trigger on a table T1 for insert and update. The trigger
>selects values from table T2, which happens to be in a different database.
>It seems I have to create users in that other database for every user who
>updates or inserts records into T1. Is there any way around this, using
>views or stored procedures, in SQL Server 2000?
> Thanks
> Timo|||Hi,
please refer article FYI :
http://www.netdscure.co.in/Articles/AuditDML.htm
--
Andy Davis
Activecrypt Team
---SQL Server Encryption Software
http://www.activecrypt.com
"Timo" wrote:

> I created a trigger on a table T1 for insert and update. The trigger
> selects values from table T2, which happens to be in a different
> database. It seems I have to create users in that other database for
> every user who updates or inserts records into T1. Is there any way
> around this, using views or stored procedures, in SQL Server 2000?
> Thanks
> Timo
>

Database Users and Logins

Hi

I can't figure out what the purpose of having seperate users is as I can't actually login to the database using one.

Here is my scenario.

I have a single login called LoginA and I have a database which I want to carve up using schema's. At the database level I need to create a user, associate a login with this user and can set a default schema and specifiy what schemas this USER can access. The login created can access multiple schemas.

So..

I created a database login called loginA.

I created a user for the database called UserA set it's login name to LoginA and

I then created 3 schemas called SchemaA, SchemaB and SchemaC and set their schema owner name to UserA.

I went back to UserA and set their default Schema to SchemaA

How can I login using the new user created as it has no password associated with it. If I login using LoginA then I have no default Schema set becuase the schema is associated with a USER not a LOGIN.

I can understand why you can only have one login account assicated with one user account for each database but I can;t understand why you can specify a user name if you can't use it to login.

Has anyone got any ideas?

Thanks

Logins are used to connect to the server - they provide an identity at the server level. Users provide an identity at the database level. A login will be mapped to a user when he connects to the database.

To have the default schema take effect after login, you should change context to the database where you create UserA (let's say its name is DbA). To automatically do this at login time, you need to additionally change the default database of LoginA to be DbA instead of the master database. A schema is a database entity, so the default schema of a login will be specific to each database to which he will connect.

Thanks
Laurentiu

Database users after restore

We restore a production database (with around 50 users) to
a Training database on another SQL 2000 Server.
However, we find that those users on the Training Database
disappear (All has been lost except SA). However, from
one Database Role, it shows that those users (around 50)
still are members of that role.
Is it sensible for those database users disappear (As
there is no corresponding SQL Server Login created for
them) OR how can I get back those users ?
ThanksThey have a mis-match to the id for the logins in master..syslogins. Use sp_change_users_locing to
fix. There's a free GUI for that available at http://www.dbmaint.com/free_utilities.asp.
--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as ugroup=microsoft.public.sqlserver
"Roger Lee" <rogerlee@.nospam.com> wrote in message news:093501c36601$7bec4cb0$a301280a@.phx.gbl...
> We restore a production database (with around 50 users) to
> a Training database on another SQL 2000 Server.
> However, we find that those users on the Training Database
> disappear (All has been lost except SA). However, from
> one Database Role, it shows that those users (around 50)
> still are members of that role.
> Is it sensible for those database users disappear (As
> there is no corresponding SQL Server Login created for
> them) OR how can I get back those users ?
> Thanks|||>--Original Message--
>We restore a production database (with around 50 users)
to
>a Training database on another SQL 2000 Server.
>However, we find that those users on the Training
Database
>disappear (All has been lost except SA). However, from
>one Database Role, it shows that those users (around 50)
>still are members of that role.
>Is it sensible for those database users disappear (As
>there is no corresponding SQL Server Login created for
>them) OR how can I get back those users ?
>Thanks
>.
>You can copy across users/logins from the other DB using
DTS.

Database Users

Hi Guys.
I have 2 databases on my sql server, each database has different set of
users.
I want to copy the data between database "a" to database "b".
When i backup "a" and restore into "b" the database users also copy from "a"
and come to "b"
I want to replace these users, but i cannot delete them. because the
database user owns objects in database.
is there a way to rename the database users, or replace them?
Thanks in advance.This is a good page to help your problem
http://support.microsoft.com/default.aspx?scid=kb;en-us;246133
HTH
--
Ray Higdon MCSE, MCDBA, CCNA
--
"MAQ" <pakmaq@.hotmail.com> wrote in message
news:uwyiJVscDHA.1204@.TK2MSFTNGP12.phx.gbl...
> Hi Guys.
> I have 2 databases on my sql server, each database has different set of
> users.
> I want to copy the data between database "a" to database "b".
> When i backup "a" and restore into "b" the database users also copy from
"a"
> and come to "b"
> I want to replace these users, but i cannot delete them. because the
> database user owns objects in database.
> is there a way to rename the database users, or replace them?
> Thanks in advance.
>

Database user and Corresponding login

Hi everyone,

I have a simple question regarding the database users on sqlserver 2005.

When i run a 'sp_helpuser' stored procedure in a database to know the usernames and their corresponding loginsName, i find there are some usernames with corresponding loginName as null.I know for sure that for 'Guest' username the corresponding loginName will be Null, but i find many normal database users with Null login names.

Can anyone throw some light on this scenario?.and what about 'dbo' user in a database? can dbo user have a 'NULL' login name or 'sa' login by default?. Please help me

Thanks in advance.

Regards

Arvind L

You can use sp_change_users_login 'Report' to find out if there are orphaned users. (users with no login)

There are users like 'Guest', 'dbo', 'INFORMATION_SCHEMA' that will not have logins associated because these are defined by the system, but if there are users like 'George', etc. then these are most likely users that were created at one time by users or admins. The above command will help you to know which users are orphaned and can be fixed by creating logins and associating them with the user.

When a sysadmin user logs in, they do not necessarily have a user for every database because they can query any database. Those with specific permissions db_datareader or db_datawriter, etc. will need to have a user in the database that they are trying to query because they are limited to permissions assigned.

HTH.

|||

One possible senario is, this database might be restored from another sql server instance and that server may be having these logins-users mapping. Once the database is shifted from one server to another the user-login mapping breaks though the logins are there in the new instance. you need to remap the orphaned user with the logins using sp_change_users_login

Madhu

|||Thanks Ben and Madhu..for the useful piece of info!!!