Showing posts with label system. Show all posts
Showing posts with label system. Show all posts

Thursday, March 29, 2012

finding hidden chars in sql query


I am working on a login system in flex and asp. I am encrypting the password before it is inserted it into the SQL database. But then when i do SELECT statement with username and encrypted password it returns 0 users found.
I outputted the sql statement and they passwords look excatly the same. But the SQL Select count(*) returns a 0.

link to the encrypting is used:
http://www.4guysfromrolla.com/webtech/110599-1.2.shtml

other information:
script language: asp + flex
database: sql server 2005

So i am thinking that their are hidden chars in the password. Is their a way to check this or even convert/exclude them ?
Any links or tips would be very helpfull

Use the sample to solve your issue...

Alter Function dbo.En_De_Crypt(@.Input varchar(max), @.Key int ) Returns Varchar(Max) as

Begin

Declare @.Len as Int;

Declare @.I as Int;

Declare @.Output as Varchar(max)

Select @.Len = Len(@.Input), @.I =1, @.Output=''

Declare @.Number Table (N int);

While(@.I<=@.Len)

Begin

Insert into @.Number Values(@.I);

Set @.I = @.I + 1;

End

Select @.Output = @.Output + Char(Ascii(Substring(@.Input,N,1)) ^ @.Key)

From @.Number

return @.Output

End

Go

Create Table #Passwords(

Password varchar(20)

);

Insert Into #Passwords Values(dbo.En_De_Crypt('One1234$$',100));

Insert Into #Passwords Values(dbo.En_De_Crypt('M1cr0$0ft',100));

Insert Into #Passwords Values(dbo.En_De_Crypt('Or@.c1e',100));

Insert Into #Passwords Values(dbo.En_De_Crypt('@.pp1e',100));

Select dbo.En_De_Crypt(Password,100) ,Password From #Passwords

/*

Orginal value Decrypted Value

One1234$$ + _VWP@.@.

M1cr0$0ft )Up'16T@.T '10

Or@.c1e +_$p_par

@.pp1e $__U_par */

--None of the query will return the data here..

Select Count(*) From #Passwords Where Password = '+

_VWP@.@.'

Select Count(*) From #Passwords Where Password = ')Up'16T@.T '10'

Select Count(*) From #Passwords Where Password = '?_p$'

Select Count(*) From #Passwords Where Password = '$__U_par'

--Use the following query to get the result..

Select Count(*) From #Passwords Where dbo.En_De_Crypt(Password,100)='M1cr0$0ft'

|||thnx Manivannan for the reply.
i will try it out.

Wednesday, March 28, 2012

Finding Duplicates

I have a pretty extensive database system I am querying, though what I am
looking for should be easy to find. I am looking for instances in the
Clients table that appear more than once (duplicate clients). I am using the
following:
Select First_Name + ' ' + Last_Name as Client,
Count(SSNum) as Count
From Clients
Group By First_Name, Last_Name, SSNum
Having Count(SSNum)>=2
Where I am confused is this; if I remove the Group By SSNum I have 126
instances. With the Group By SSNum I have 56. When I link in the account
table to get the site name and worker name I have 14 instances. Is there
another more reliable way to tell what names and ssn's happen more than
once?
TIA"John C Harris" <harris1113@.tampabay.rr.com> wrote in message
news:4416EDF4-0119-45CC-87A9-D23E2EEFB63B@.microsoft.com...
>I have a pretty extensive database system I am querying, though what I am
>looking for should be easy to find. I am looking for instances in the
>Clients table that appear more than once (duplicate clients). I am using
>the following:
> Select First_Name + ' ' + Last_Name as Client,
> Count(SSNum) as Count
> From Clients
> Group By First_Name, Last_Name, SSNum
> Having Count(SSNum)>=2
> Where I am confused is this; if I remove the Group By SSNum I have 126
> instances. With the Group By SSNum I have 56. When I link in the account
> table to get the site name and worker name I have 14 instances. Is there
> another more reliable way to tell what names and ssn's happen more than
> once?
> TIA
>
If you include SSNum in the GROUP BY then you will get one row for every
unique (First_Name, Last_Name, SSNum) that is duplicated.
If you don't include SSNum in the GROUP BY then you will get one row for
every unique (First_Name, Last_Name) that is duplicated.
Both methods are perfectly reliable but they tell you different things. It
all depends on what answer you want.
I guess the problem with the JOIN version is that you are doing an INNER
JOIN that is eliminating some rows. Difficult to say without seeing the
code.
Please post DDL, sample data and required results if you need more help.
--
David Portas|||Ah OK. I think I have it. Does this make sense:
I run the code below and get 56 names and ssns duplicated
I add the Worker ID and get 14 names
I add the Site Name and also get 14 names
So this is basically telling me that I have 56 clients in the table that
match more than once on name and SSN, but by adding the site and worker that
goes down to 14, meaning that I have 14 duplicates with the same name AND
same site/worker. So from that I can assume of the 56 names, 42 of them are
in more than one site, but only once in those sites?
That actually makes sense in looking through the raw data, because it
appears the same client went to more than one site.
"John C Harris" <harris1113@.tampabay.rr.com> wrote in message
news:4416EDF4-0119-45CC-87A9-D23E2EEFB63B@.microsoft.com...
>I have a pretty extensive database system I am querying, though what I am
>looking for should be easy to find. I am looking for instances in the
>Clients table that appear more than once (duplicate clients). I am using
>the following:
> Select First_Name + ' ' + Last_Name as Client,
> Count(SSNum) as Count
> From Clients
> Group By First_Name, Last_Name, SSNum
> Having Count(SSNum)>=2
> Where I am confused is this; if I remove the Group By SSNum I have 126
> instances. With the Group By SSNum I have 56. When I link in the account
> table to get the site name and worker name I have 14 instances. Is there
> another more reliable way to tell what names and ssn's happen more than
> once?
> TIA
>sql

Finding database size in SQL Express

Our system guy wants me to find out just exactly how much room is being taken up by the SQL Express databases (I am using two). I am not sure how to do this. Is there any way to find the size, or, lacking that, how many records overall? We will probably need to move up to SQL 2005 soon, but he needs to figure out the memory requirements, etc.

Thanks,

Michael

try select [size] from sys.database_files

This will give you a row for each primary datafile and log, to get it all in one statement you could use

select Sum([size]) as total_file_size from sys.database_files

|||

Thanks, that worked.

Michael

Monday, March 26, 2012

Finding affected tables

I am attempting to document a sql server 2000 based accounting system.
Is there any way to see what tables a stored procedure affects
without diving into the code?

Regards,

Ty"Tyler Hudson" <tylerh@.allpax.com> wrote in message
news:804fa945.0403020849.fcf8f0b@.posting.google.co m...
> I am attempting to document a sql server 2000 based accounting system.
> Is there any way to see what tables a stored procedure affects
> without diving into the code?
>
> Regards,
> Ty

You can try sp_depends, although it may not be completely accurate,
depending on the order in which objects were created.

Simon

Friday, March 23, 2012

Finding a tape drive

I am writing an interface for the SQL backup in my application. I am
currently trying to determine if a tape drive exists on the system so the
system can add it as a backup device. If I use enterprise manager to add
the tape drive as a device my application can see the device but still can't
see the tape drive directly. My system can see the hard drives and DVD
drive on my system. I have tried sp_helpdevices, xp_availablemedia, and
sysdevices.
Should I be looking somewhere else or does the user have to add the tape
from Enterprise manager first?
Regards,
JohnDepending on what interface you're developing, you can use SQL-DMO in
various languages to iterate through devices on your SQL Server and
tapes as well.
Here's a few helpful links that I found useful when I developed a SQL
Db management interface for the web.
http://msdn.microsoft.com/library/d...br />
3tlx.asp
http://sqldev.net/sqldmo.htm|||Thanks for the replay.
I have been implementing this via the SqlClient in C# using the basic
"BACKUP <db> TO <device>" interface. I obtained a list of devices from the
sys_devices or xp_availablemedia and xp_subdir which all seems to work fine
except I don't see the tape device unless it's added as a device.
I have never worked with SQL-DMO and the example seems to have problem
compiling which I assume is because it was written for an older version of
C# / .NET. What is the advantage of using the SQL-DMO as opposed to just
using the SqlClient built into C#?
Regards,
John
"sze" <szeying.tan@.gmail.com> wrote in message
news:1122596876.912374.115650@.z14g2000cwz.googlegroups.com...
> Depending on what interface you're developing, you can use SQL-DMO in
> various languages to iterate through devices on your SQL Server and
> tapes as well.
> Here's a few helpful links that I found useful when I developed a SQL
> Db management interface for the web.
> http://msdn.microsoft.com/library/d... />
b_3tlx.asp
> http://sqldev.net/sqldmo.htm
>|||you may have problems compiling if you did not reference sqldmo.dll in
your .NET project.
it should be somewhere in your sql server installation, something like
C:\Program Files\Microsoft SQL Server\80\Tools\Binn\ ...
as for advantages, i don't really know. SQL-DMO is an API for SQL
Server administration. SQLClient is a data provider for C#... i'm
usually partial to using an API when i want to interface with a
particular application... since the API encapsulates all objects
available in the particular application.. and in this case, all objects
available in SQL Server (this means everything you can do in Enterprise
Manager). but of course, it's really your call.|||Thanks again, the problem was the strong naming I already knew I needed to
link into it. I found a link for the strong naming problem on the microsoft
site so it works now.
Regards,
John|||EXECUTE master.dbo.xp_get_tape_devices seems to do the trick.
Regards,
Johnsql

Monday, March 19, 2012

find templates for global or system functions and sp in 05

In 2000 you could look at templates and find templates for global or system functions where are they in 05?Databases / system db / master / programability / stored proc or fucnt orr...

Monday, March 12, 2012

find right database for stored procedure

I have a message queueing system set up so that applications can insert
message information into a database using a stored procedure in the master
database...
CREATE PROCEDURE sp_PutInQueue
<...message parameters...>
AS
DECLARE @.dbid smallint
--get the database context who is running this procedure
SET @.dbid = db_id()
INSERT INTO MessageQueue.Queue (
<...message parameter fields...>,
dbID)
VALUES (
<...message parameters...>,
@.dbid)
GO
After I process the message, I want to use the stored dbID in the table to
reference the calling application and execute a stored procedure in that
database so it will know it's message has been processed. Since I can't use
the USE clause in a stored procedure, how can I accomplish what I am trying
to do'--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1
Use dynamic SQL & a scope:
-- start in master db
declare @.sql varchar(200)
declare @.dbid varchar(30)
set @.dbid = 'pubs'
set @.sql = 'use ' + @.dbid + ' select top 2 * from authors'
-- or for an SP: set @.sql = 'exec ' + @.dbid + '..MySp param1, param2'
execute (@.sql)
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/ AwUBQksjIoechKqOuFEgEQKqCwCghzNcxXMIEnfQ
pw55MCLSObS1Ld8Anit2
R+yW+XNslP/Rm6wTVEBmA243
=MqHA
--END PGP SIGNATURE--
Random wrote:
> I have a message queueing system set up so that applications can insert
> message information into a database using a stored procedure in the master
> database...
> CREATE PROCEDURE sp_PutInQueue
> <...message parameters...>
> AS
> DECLARE @.dbid smallint
> --get the database context who is running this procedure
> SET @.dbid = db_id()
> INSERT INTO MessageQueue.Queue (
> <...message parameter fields...>,
> dbID)
> VALUES (
> <...message parameters...>,
> @.dbid)
> GO
> After I process the message, I want to use the stored dbID in the table to
> reference the calling application and execute a stored procedure in that
> database so it will know it's message has been processed. Since I can't u
se
> the USE clause in a stored procedure, how can I accomplish what I am tryin
g
> to do'

find out lock start time

I think it would be great to investigate into system performance and dead
lock if we can find out the start time for the current locks. Is there a way
to do that? thanks!
I tried the following 2 methods:
1) EXEC sp_lock
2) In the enterprice manager | management | current activities |
locks/object
Neither view gives me what I'm looking for.
thanks again!
Maybe these will help:
http://msdn.microsoft.com/library/de...tabse_5xrn.asp
Troubleshooting Deadlocks
http://www.support.microsoft.com/?id=224453 Blocking Problems
http://www.support.microsoft.com/?id=271509 How to monitor SQL 2000
Blocking
Andrew J. Kelly SQL MVP
"Zeng" <zeng@.nononospam.com> wrote in message
news:%23ATn9732GHA.2096@.TK2MSFTNGP05.phx.gbl...
> I think it would be great to investigate into system performance and dead
> lock if we can find out the start time for the current locks. Is there a
> way to do that? thanks!
> I tried the following 2 methods:
> 1) EXEC sp_lock
> 2) In the enterprice manager | management | current activities |
> locks/object
> Neither view gives me what I'm looking for.
> thanks again!
>

find out lock start time

I think it would be great to investigate into system performance and dead
lock if we can find out the start time for the current locks. Is there a way
to do that? thanks!
I tried the following 2 methods:
1) EXEC sp_lock
2) In the enterprice manager | management | current activities |
locks/object
Neither view gives me what I'm looking for.
thanks again!Maybe these will help:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/trblsql/tr_servdatabse_5xrn.asp
Troubleshooting Deadlocks
http://www.support.microsoft.com/?id=224453 Blocking Problems
http://www.support.microsoft.com/?id=271509 How to monitor SQL 2000
Blocking
Andrew J. Kelly SQL MVP
"Zeng" <zeng@.nononospam.com> wrote in message
news:%23ATn9732GHA.2096@.TK2MSFTNGP05.phx.gbl...
> I think it would be great to investigate into system performance and dead
> lock if we can find out the start time for the current locks. Is there a
> way to do that? thanks!
> I tried the following 2 methods:
> 1) EXEC sp_lock
> 2) In the enterprice manager | management | current activities |
> locks/object
> Neither view gives me what I'm looking for.
> thanks again!
>

find out lock start time

I think it would be great to investigate into system performance and dead
lock if we can find out the start time for the current locks. Is there a way
to do that? thanks!
I tried the following 2 methods:
1) EXEC sp_lock
2) In the enterprice manager | management | current activities |
locks/object
Neither view gives me what I'm looking for.
thanks again!Maybe these will help:
http://msdn.microsoft.com/library/d...
tabse_5xrn.asp
Troubleshooting Deadlocks
http://www.support.microsoft.com/?id=224453 Blocking Problems
http://www.support.microsoft.com/?id=271509 How to monitor SQL 2000
Blocking
Andrew J. Kelly SQL MVP
"Zeng" <zeng@.nononospam.com> wrote in message
news:%23ATn9732GHA.2096@.TK2MSFTNGP05.phx.gbl...
> I think it would be great to investigate into system performance and dead
> lock if we can find out the start time for the current locks. Is there a
> way to do that? thanks!
> I tried the following 2 methods:
> 1) EXEC sp_lock
> 2) In the enterprice manager | management | current activities |
> locks/object
> Neither view gives me what I'm looking for.
> thanks again!
>

Friday, March 9, 2012

find out active Sql statements

Hi,
Where does Sql server store the most current active T-SQL
statements? Is there a system table or stored procedure(documented or
undocumented)that will show you the active sql statements being
executed. For eg: in oracle you can query v$sql to see all the sql
statements executed by each session.
I know that you can use Enterprise manager, but was wondering if you
can run a query via query analyzer to look at it.
Any help is appreciated.

Thanks
Geetha<gdabbara@.brownshoe.com> wrote in message
news:1106264397.579113.143730@.c13g2000cwb.googlegr oups.com...
> Hi,
> Where does Sql server store the most current active T-SQL
> statements? Is there a system table or stored procedure(documented or
> undocumented)that will show you the active sql statements being
> executed. For eg: in oracle you can query v$sql to see all the sql
> statements executed by each session.
> I know that you can use Enterprise manager, but was wondering if you
> can run a query via query analyzer to look at it.
> Any help is appreciated.
> Thanks
> Geetha

Check out fn_get_sql() in Books Online - if it isn't there, you'll need to
download the latest BOL version from Microsoft:

http://www.microsoft.com/sql/techin.../2000/books.asp

DBCC INPUTBUFFER is another option, but it can only display the first 255
characters of whatever batch is being executed.

Simon|||[posted and mailed]

(gdabbara@.brownshoe.com) writes:
> Where does Sql server store the most current active T-SQL
> statements? Is there a system table or stored procedure(documented or
> undocumented)that will show you the active sql statements being
> executed. For eg: in oracle you can query v$sql to see all the sql
> statements executed by each session.
> I know that you can use Enterprise manager, but was wondering if you
> can run a query via query analyzer to look at it.

Simon pointed you to the basics. To get it all nicely packaged, I
have stored procedure aba_lockinfo that will give you the information.
Have a look at http://www.sommarskog.se/sqlutil/aba_lockinfo.html.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Thanks you all for the information. It was very helpful.

Find object owner

Is there a query I can write that joins 2 system tables to return the owners of objects (e.g. tables) and the object's name?

Thanks,

Dave

IN SQL SERVER 200 the SCHEMA IN the information_VIEW represents the owner OF an objects e.g. FOR tables

SELECT TABLE_SCHEMA FROM [INFORMATION_SCHEMA].TABLES

IN SQL SERVER 2005, you will have TO determine the owner OF the SCHEMA instead using

SELECT Name FROM sys.Schemas

INNER JOIN sys.server_principals

ON [Schemas].principal_id = [server_principals].Principal_id

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

In SQL SERVER 2005, because of the ALTER AUTHORIZATION clause, the schema owner may not always be the object owner

See, http://msdn2.microsoft.com/en-us/library/ms187359.aspx

So, an alternative to the above query for SQL SERVER 2005 is

select user_name(objectproperty(object_id,'OwnerId')), name from sys.objects

This always returns the correct owner of the object and takes 'ALTER AUTHORIZATION' into account.

Sunday, February 26, 2012

find all sps where a field is used

In my database i want list of all stored procedures where i have used a
specific field.
Is there any way to do this.. any system sp which does thisYou have to search the prcedure definition for that, because AFAIK
there is no system binding or something like this where the information
is stored which columns are used. So the approach could be SELECT
Routine_name from INFORMATION_SCHEMA.Routines Where Routine_definition
like '%SomeValue%'
HTH, jens Suessmeyer.|||The information isn't stored in any system table, except for the source code
for the procedure
(syscomments). So you can use a LIKE predicate against the text column in sy
scomments, but be
careful as syscomments can break the line (use several rows for a procedure)
in the middle of a word
(at least it used to, perhaps newer versions are better).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Vikram" <aa@.aa> wrote in message news:OmDLgniAGHA.204@.TK2MSFTNGP15.phx.gbl...d">
> In my database i want list of all stored procedures where i have used a
> specific field.
> Is there any way to do this.. any system sp which does this
>|||This might not be very pretty, but it should do the job:
CREATE TABLE #Depends
([Name] nvarchar(128),[type]nvarchar(128))
INSERT INTO #Depends
EXEC SP_Depends 'Table1'
SELECT [Name] from #depends
WHERE [type] = 'stored procedure'
AND OBJECT_ID([Name]) IN (Select [id] from syscomments where [text]
LIKE '%FieldName%')
Drop Table #depends
Markus|||(The following applies to SQL 2000. I haven't tried it in SQL 2005.)
I'm assuming that enterprise manager uses sp_depends to display dependancy
information. If this is true, your suggestion will only work if objects are
created in the correct sequence.
For example, it works if:
1. Create Table1.
2. Create proc MyProc1 that select Data from Table1.
If you drop table1 and recreate it, dependancy information is lost and will
not be shown. Same holds true for stored procedures. If you create a store
d
procedure that references another stored procedure that doesn't exist yet,
you will not have dependancy information even after you create the other
stored procedure.
IMHO, the only sure fired way is to script the database to a text file and
search it for the column name and/or table names that you are interested in.
Also, if any view, stored procedure, or user-defined function uses an *,
then you can't search by column name.
Hope that helps,
Joe
"m.bohse@.quest-consultants.com" wrote:

> This might not be very pretty, but it should do the job:
> CREATE TABLE #Depends
> ([Name] nvarchar(128),[type]nvarchar(128))
> INSERT INTO #Depends
> EXEC SP_Depends 'Table1'
> SELECT [Name] from #depends
> WHERE [type] = 'stored procedure'
> AND OBJECT_ID([Name]) IN (Select [id] from syscomments where [text]
> LIKE '%FieldName%')
> Drop Table #depends
> Markus
>