Showing posts with label hii. Show all posts
Showing posts with label hii. Show all posts

Thursday, March 22, 2012

Default Backup Location

Hi

I am almost ashamed to ask but I cannot find the setting

Is there a way to set the default backup location in sql 2005? I dont want to change the folder every time I specify a new media.

Thanks

Alex

Hi Alex,

I don't think you can do it with the SSMS. Here's a registry key you can modify, however:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer\BackupDirectory

Regards,
Jake Marx

|||

I suggest that you do not use the default setting in SQL Server (even if you change it) as it makes administration and maintenance more of a headache for (us) DBAs Smile

Come up with a standard approach suitable for your organization on doing backups of databases

Default ASPNETDB database

Hi

I want to set up my web app to use a web parts personalization, I notice that a default database named aspnetdb is made, I also made one in my sql server using the aspnet_regsql.exe to make it. Now what I need to find out is how to make my app point to the database in the sql server instead of making that default one.

Thanks

You need to modify your connectionstring in the web.config to point to the instance of the DB you wish to connect to.

Marco

Please mark as answered if this helps!

|||

Hi

thanks for the response, how exactly should I use the connection string and where in the file?

thanks

|||

Hello - are you using VWD? Your web.config file will be stored where all your .aspx files are stored. Open the file and make the below changes (in bold)

<connectionStrings>

<addname="DatabaseNameHere"connectionString="Data Source=ComputerNameHere\SQLInstanceNameHere;Initial Catalog=DatabaseNameHere;Integrated Security=True"providerName="System.Data.SqlClient"/>

</connectionStrings>

Marco

|||

Hi, thanks for the string, the connection works but the app still uses that local aspnetbd as the default database, any ideas as to why.

thanks

|||

Hello - try adding a customized membership provider in your web.config, which if implemented as below is just a copy of the default provider but with a different name, Then point the customized membership provider to your connection string. Read this article which fully explains what your are trying to do -http://aspnet.4guysfromrolla.com/articles/120705-1.aspx

<membershipdefaultProvider="CustomizedMembershipProvider">

<providers>

<addname="CustomizedMembershipProvider"type="System.Web.Security.SqlMembershipProvider"connectionStringName="XXXXXXXX"applicationName="XXXXXXXXXX"/>

</providers>

</membership>

|||

Thanks that put me in the right path now im getting a error on the connection string

ERROR :The specified connectionStringName, 'xxxx', was not registered.

Any ideas,

Thanks

|||

Hello - have you replaced the 'xxxx' with the name of your connection string? the name of your connection string is in your web.config

<connectionStrings>

<addname="XXXXX" - this is where the name of your connection string will be.

Marco

|||

Hi, thanks for all your help again, that set me on the right path and I found the solution.

What I found out is that the machine.config file was looking for a connection named LocalSqlServer so in order to override that I had to clear that connection, I was using the <remove> element to remove the LocalSqlServer but didn't seem to work, so I just used the <clear/>, also I named the new connection LocalSqlServer because without it it was giving me a "connectionstring not register" error, so as soon as I named it LocalSqlServer it went through. I'm not sure if it can go in with a different name as every time I tried to name it differently it gave me errors, it was looking for LocalSqlServer regardless. I also had to give the Aspnet user access to that database.

Here is a sample of what I used

<connectionStrings
<clear/>
<add name="LocalSqlServer" connectionString="Data Source=path/;database=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient" /
</connectionStrings
<system.web
<roleManager enabled="true" />
<compilation debug="true" strict="false" explicit="true"/
<authentication mode="Forms" /
<webParts>
<personalization defaultProvider="AspNetSqlPersonalizationProvider">
<providers
<clear/>
<add connectionStringName="LocalSqlServer"
name="AspNetSqlPersonalizationProvider" type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="/appname" /
</providers>
</personalization>
</webParts
</system.web
</configuration>

Maybe this might help someone else.

Thanks agian for your help

Wednesday, March 21, 2012

Dedicated Administrator Connection

Hi:

I am trying to connect to my local instance of SQL Server 2005 using Dedicated Administrator Connection by using

Admin:Servername\Instancename

and I end up with the following error.

Dedicated administrator connections are not supported.

I enabled the connection in the SQL Configuration Manager and still get the error.

Any ideas on how to resolve this error?.

Note: SQL Browser service is running.

Thanks

Ak

Which SKU of sql server 2005 are you running ?

Also, are the client and the server running on the same machine or different machines ?

|||

Hi Asvin:

I am running SQL Server 2005 Standard Edition and both the client and server are running on the same machine.

Thanks

|||You can check the sqlserver log to see if DAC is enabled/listening (and on which tcp port).

Use sqlcmd -A to test. Also, you cannot use DAC for Object Explorer connection. It only works on query window. So, connect normally first, then open a new query window with "admin:<server>\<instance>"|||

Hi OJ:

Thanks for your reply.

This is what my SQL Server log says.

Date 7/7/2006 4:56:11 PM
Log SQL Server (Current - 7/12/2006 12:00:00 AM)

Source Server

Message
Dedicated admin connection support was established for listening remotely on port 1771.

So DAC is listening on port 1771 right?. I tried your second method of connecting to through object explorer but I got the same error message.

Then I tried the following from command prompt:

sqlcmd -SMyMachine\SQL2K5 -A -E

I got the following error message:

HResult 0xFFFFFFFF, Level 16, State 1
SQL Network Interfaces: An error occurred while obtaining the dedicated administrator connection (DAC) port.
Make sure that SQL Browser is running, or check the error log for the port number [xFFFFFFFF].
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings
SQL Server does not allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.

Please let me know what I am doing wrong.

Thanks

|||

MS Experts:

Can anyone please help me with this issue. I would really appreciate all your help.

Thanks

AK

|||Sorry for the late reply.

I've seen the same error when the server\instance is incorrect. Since this is a local instance, please try one of the following:

sqlcmd -S".\SQL2K5" -A -E

sqlcmd -S"MyMachine,1771" -A -E

Be sure to start the instance first.

net start mssql$sql2k5

|||

Did you enable remote connections ?

http://www.sqlserver2005.de/SharedFiles/Remoteconnection.jpg

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

Thanks OJ and Jens. I tried all options that you have suggested (my remote connections are enabled) but still get the same error.

The funny thing is when I try through the command prompt using sqlcmd (with the new commands you gave) it appears to be connected but when I connect using SQL Management Studio while the command window is still open, it allows me to establish a new connection through Management studio. I think once DAC is established i should not be able to make a new connection using management studio. DAC should allow only a single connection. This tells me that a DAC was not establised through SQLCMD from command prompt.

So to make sure that I can indeed connect using DAC I used the SQL Management Studioand tried the following:

ADMIN:.\SQL2K5 and end up with the same error.

Dedicated adminstrator connections are not supported.

This means I am not able to connect using DAC still.

I cant post the attachment or else I would have posted the attachment.

|||There can only be ONE admin connection. If you successfully connect via "sqlcmd -A" then you will not be able to make another admin connection via sqlwb (vice versa).

Admin connection has nothing to do with regular user connection. So, it's normal that you still can connect via sqlwb. However, it will not be possible for you to open another admin connection (i.e. admin:\.sql2k5) via sqlwb if you already connect with sqlcmd.

As I have said before, you need to connect normally (without admin) when you first open up sqlwb. Once that's done, you can open a new query window (File -> New -> Database Engine Query) and connect as an admin connection.

If you still have problem, please post the entire sql log here.|||

Do you obtain this error message:

"Dedicated administrator connections are not supported. (ObjectExplorer)"

If so you try to connect the Object Explorer. Try to open a new query windows as oj told you.

|||

Thanks everyone. I seem to have connected through the cmd prompt through DAC and when I query using @.@.Servername I can see my machine name in the cmd prompt window. I am just wondering if there is a command in SQL Server 2005 that tells me whether I am connected using dedicated admin connection or that my present connection is a DAC. If so, I would appreciate if if anyone lets me know it.

Thanks

AK.

|||

The query below should return 1 row if you are connected using dedicated admin connection. It should not return any rows if you are not connected using DAC.

select * from sys.dm_exec_connections ec join sys.endpoints e on (ec.endpoint_id=e.endpoint_id) where e.name='Dedicated Admin Connection' and session_id=@.@.spid

|||

Thanks Ashvin. That did exactly confirm that I was connected using DAC. It returned one row. So my million dollar question is why cant I connect to DAC using ADMIN keyword. I tried all that have been suggested in this thread and still it says DAC connections are not supported (Object Explorer). Its a mystery!!!.

However thanks for all the suggestions.

|||

Hi,

DAC is a feature which is disabled by default. Did you enable it so far ? I made a screencast for you showing how to enable this feature. This is the second of a series which I decided to make. So have Fun !

A link with the screencasts taken so far will be on my site as I will have time for that.

use this link here in the meantime: http://www.SQLServer2005.de/ScreenCasts/Enable_DAC.htm

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

Dedicated Administrator Connection

Hi:

I am trying to connect to my local instance of SQL Server 2005 using Dedicated Administrator Connection by using

Admin:Servername\Instancename

and I end up with the following error.

Dedicated administrator connections are not supported.

I enabled the connection in the SQL Configuration Manager and still get the error.

Any ideas on how to resolve this error?.

Note: SQL Browser service is running.

Thanks

Ak

Which SKU of sql server 2005 are you running ?

Also, are the client and the server running on the same machine or different machines ?

|||

Hi Asvin:

I am running SQL Server 2005 Standard Edition and both the client and server are running on the same machine.

Thanks

|||You can check the sqlserver log to see if DAC is enabled/listening (and on which tcp port).

Use sqlcmd -A to test. Also, you cannot use DAC for Object Explorer connection. It only works on query window. So, connect normally first, then open a new query window with "admin:<server>\<instance>"|||

Hi OJ:

Thanks for your reply.

This is what my SQL Server log says.

Date 7/7/2006 4:56:11 PM
Log SQL Server (Current - 7/12/2006 12:00:00 AM)

Source Server

Message
Dedicated admin connection support was established for listening remotely on port 1771.

So DAC is listening on port 1771 right?. I tried your second method of connecting to through object explorer but I got the same error message.

Then I tried the following from command prompt:

sqlcmd -SMyMachine\SQL2K5 -A -E

I got the following error message:

HResult 0xFFFFFFFF, Level 16, State 1
SQL Network Interfaces: An error occurred while obtaining the dedicated administrator connection (DAC) port.
Make sure that SQL Browser is running, or check the error log for the port number [xFFFFFFFF].
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings
SQL Server does not allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.

Please let me know what I am doing wrong.

Thanks

|||

MS Experts:

Can anyone please help me with this issue. I would really appreciate all your help.

Thanks

AK

|||Sorry for the late reply.

I've seen the same error when the server\instance is incorrect. Since this is a local instance, please try one of the following:

sqlcmd -S".\SQL2K5" -A -E

sqlcmd -S"MyMachine,1771" -A -E

Be sure to start the instance first.

net start mssql$sql2k5

|||

Did you enable remote connections ?

http://www.sqlserver2005.de/SharedFiles/Remoteconnection.jpg

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

Thanks OJ and Jens. I tried all options that you have suggested (my remote connections are enabled) but still get the same error.

The funny thing is when I try through the command prompt using sqlcmd (with the new commands you gave) it appears to be connected but when I connect using SQL Management Studio while the command window is still open, it allows me to establish a new connection through Management studio. I think once DAC is established i should not be able to make a new connection using management studio. DAC should allow only a single connection. This tells me that a DAC was not establised through SQLCMD from command prompt.

So to make sure that I can indeed connect using DAC I used the SQL Management Studioand tried the following:

ADMIN:.\SQL2K5 and end up with the same error.

Dedicated adminstrator connections are not supported.

This means I am not able to connect using DAC still.

I cant post the attachment or else I would have posted the attachment.

|||There can only be ONE admin connection. If you successfully connect via "sqlcmd -A" then you will not be able to make another admin connection via sqlwb (vice versa).

Admin connection has nothing to do with regular user connection. So, it's normal that you still can connect via sqlwb. However, it will not be possible for you to open another admin connection (i.e. admin:\.sql2k5) via sqlwb if you already connect with sqlcmd.

As I have said before, you need to connect normally (without admin) when you first open up sqlwb. Once that's done, you can open a new query window (File -> New -> Database Engine Query) and connect as an admin connection.

If you still have problem, please post the entire sql log here.|||

Do you obtain this error message:

"Dedicated administrator connections are not supported. (ObjectExplorer)"

If so you try to connect the Object Explorer. Try to open a new query windows as oj told you.

|||

Thanks everyone. I seem to have connected through the cmd prompt through DAC and when I query using @.@.Servername I can see my machine name in the cmd prompt window. I am just wondering if there is a command in SQL Server 2005 that tells me whether I am connected using dedicated admin connection or that my present connection is a DAC. If so, I would appreciate if if anyone lets me know it.

Thanks

AK.

|||

The query below should return 1 row if you are connected using dedicated admin connection. It should not return any rows if you are not connected using DAC.

select * from sys.dm_exec_connections ec join sys.endpoints e on (ec.endpoint_id=e.endpoint_id) where e.name='Dedicated Admin Connection' and session_id=@.@.spid

|||

Thanks Ashvin. That did exactly confirm that I was connected using DAC. It returned one row. So my million dollar question is why cant I connect to DAC using ADMIN keyword. I tried all that have been suggested in this thread and still it says DAC connections are not supported (Object Explorer). Its a mystery!!!.

However thanks for all the suggestions.

|||

Hi,

DAC is a feature which is disabled by default. Did you enable it so far ? I made a screencast for you showing how to enable this feature. This is the second of a series which I decided to make. So have Fun !

A link with the screencasts taken so far will be on my site as I will have time for that.

use this link here in the meantime: http://www.SQLServer2005.de/ScreenCasts/Enable_DAC.htm

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

Dedicated Administrator Connection

Hi:

I am trying to connect to my local instance of SQL Server 2005 using Dedicated Administrator Connection by using

Admin:Servername\Instancename

and I end up with the following error.

Dedicated administrator connections are not supported.

I enabled the connection in the SQL Configuration Manager and still get the error.

Any ideas on how to resolve this error?.

Note: SQL Browser service is running.

Thanks

Ak

Which SKU of sql server 2005 are you running ?

Also, are the client and the server running on the same machine or different machines ?

|||

Hi Asvin:

I am running SQL Server 2005 Standard Edition and both the client and server are running on the same machine.

Thanks

|||You can check the sqlserver log to see if DAC is enabled/listening (and on which tcp port).

Use sqlcmd -A to test. Also, you cannot use DAC for Object Explorer connection. It only works on query window. So, connect normally first, then open a new query window with "admin:<server>\<instance>"|||

Hi OJ:

Thanks for your reply.

This is what my SQL Server log says.

Date 7/7/2006 4:56:11 PM
Log SQL Server (Current - 7/12/2006 12:00:00 AM)

Source Server

Message
Dedicated admin connection support was established for listening remotely on port 1771.

So DAC is listening on port 1771 right?. I tried your second method of connecting to through object explorer but I got the same error message.

Then I tried the following from command prompt:

sqlcmd -SMyMachine\SQL2K5 -A -E

I got the following error message:

HResult 0xFFFFFFFF, Level 16, State 1
SQL Network Interfaces: An error occurred while obtaining the dedicated administrator connection (DAC) port.
Make sure that SQL Browser is running, or check the error log for the port number [xFFFFFFFF].
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings
SQL Server does not allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.

Please let me know what I am doing wrong.

Thanks

|||

MS Experts:

Can anyone please help me with this issue. I would really appreciate all your help.

Thanks

AK

|||Sorry for the late reply.

I've seen the same error when the server\instance is incorrect. Since this is a local instance, please try one of the following:

sqlcmd -S".\SQL2K5" -A -E

sqlcmd -S"MyMachine,1771" -A -E

Be sure to start the instance first.

net start mssql$sql2k5

|||

Did you enable remote connections ?

http://www.sqlserver2005.de/SharedFiles/Remoteconnection.jpg

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

Thanks OJ and Jens. I tried all options that you have suggested (my remote connections are enabled) but still get the same error.

The funny thing is when I try through the command prompt using sqlcmd (with the new commands you gave) it appears to be connected but when I connect using SQL Management Studio while the command window is still open, it allows me to establish a new connection through Management studio. I think once DAC is established i should not be able to make a new connection using management studio. DAC should allow only a single connection. This tells me that a DAC was not establised through SQLCMD from command prompt.

So to make sure that I can indeed connect using DAC I used the SQL Management Studioand tried the following:

ADMIN:.\SQL2K5 and end up with the same error.

Dedicated adminstrator connections are not supported.

This means I am not able to connect using DAC still.

I cant post the attachment or else I would have posted the attachment.

|||There can only be ONE admin connection. If you successfully connect via "sqlcmd -A" then you will not be able to make another admin connection via sqlwb (vice versa).

Admin connection has nothing to do with regular user connection. So, it's normal that you still can connect via sqlwb. However, it will not be possible for you to open another admin connection (i.e. admin:\.sql2k5) via sqlwb if you already connect with sqlcmd.

As I have said before, you need to connect normally (without admin) when you first open up sqlwb. Once that's done, you can open a new query window (File -> New -> Database Engine Query) and connect as an admin connection.

If you still have problem, please post the entire sql log here.|||

Do you obtain this error message:

"Dedicated administrator connections are not supported. (ObjectExplorer)"

If so you try to connect the Object Explorer. Try to open a new query windows as oj told you.

|||

Thanks everyone. I seem to have connected through the cmd prompt through DAC and when I query using @.@.Servername I can see my machine name in the cmd prompt window. I am just wondering if there is a command in SQL Server 2005 that tells me whether I am connected using dedicated admin connection or that my present connection is a DAC. If so, I would appreciate if if anyone lets me know it.

Thanks

AK.

|||

The query below should return 1 row if you are connected using dedicated admin connection. It should not return any rows if you are not connected using DAC.

select * from sys.dm_exec_connections ec join sys.endpoints e on (ec.endpoint_id=e.endpoint_id) where e.name='Dedicated Admin Connection' and session_id=@.@.spid

|||

Thanks Ashvin. That did exactly confirm that I was connected using DAC. It returned one row. So my million dollar question is why cant I connect to DAC using ADMIN keyword. I tried all that have been suggested in this thread and still it says DAC connections are not supported (Object Explorer). Its a mystery!!!.

However thanks for all the suggestions.

|||

Hi,

DAC is a feature which is disabled by default. Did you enable it so far ? I made a screencast for you showing how to enable this feature. This is the second of a series which I decided to make. So have Fun !

A link with the screencasts taken so far will be on my site as I will have time for that.

use this link here in the meantime: http://www.SQLServer2005.de/ScreenCasts/Enable_DAC.htm

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

sql

Dedicated Administrator Connection

Hi:

I am trying to connect to my local instance of SQL Server 2005 using Dedicated Administrator Connection by using

Admin:Servername\Instancename

and I end up with the following error.

Dedicated administrator connections are not supported.

I enabled the connection in the SQL Configuration Manager and still get the error.

Any ideas on how to resolve this error?.

Note: SQL Browser service is running.

Thanks

Ak

Which SKU of sql server 2005 are you running ?

Also, are the client and the server running on the same machine or different machines ?

|||

Hi Asvin:

I am running SQL Server 2005 Standard Edition and both the client and server are running on the same machine.

Thanks

|||You can check the sqlserver log to see if DAC is enabled/listening (and on which tcp port).

Use sqlcmd -A to test. Also, you cannot use DAC for Object Explorer connection. It only works on query window. So, connect normally first, then open a new query window with "admin:<server>\<instance>"|||

Hi OJ:

Thanks for your reply.

This is what my SQL Server log says.

Date 7/7/2006 4:56:11 PM
Log SQL Server (Current - 7/12/2006 12:00:00 AM)

Source Server

Message
Dedicated admin connection support was established for listening remotely on port 1771.

So DAC is listening on port 1771 right?. I tried your second method of connecting to through object explorer but I got the same error message.

Then I tried the following from command prompt:

sqlcmd -SMyMachine\SQL2K5 -A -E

I got the following error message:

HResult 0xFFFFFFFF, Level 16, State 1
SQL Network Interfaces: An error occurred while obtaining the dedicated administrator connection (DAC) port.
Make sure that SQL Browser is running, or check the error log for the port number [xFFFFFFFF].
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings
SQL Server does not allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.

Please let me know what I am doing wrong.

Thanks

|||

MS Experts:

Can anyone please help me with this issue. I would really appreciate all your help.

Thanks

AK

|||Sorry for the late reply.

I've seen the same error when the server\instance is incorrect. Since this is a local instance, please try one of the following:

sqlcmd -S".\SQL2K5" -A -E

sqlcmd -S"MyMachine,1771" -A -E

Be sure to start the instance first.

net start mssql$sql2k5

|||

Did you enable remote connections ?

http://www.sqlserver2005.de/SharedFiles/Remoteconnection.jpg

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

Thanks OJ and Jens. I tried all options that you have suggested (my remote connections are enabled) but still get the same error.

The funny thing is when I try through the command prompt using sqlcmd (with the new commands you gave) it appears to be connected but when I connect using SQL Management Studio while the command window is still open, it allows me to establish a new connection through Management studio. I think once DAC is established i should not be able to make a new connection using management studio. DAC should allow only a single connection. This tells me that a DAC was not establised through SQLCMD from command prompt.

So to make sure that I can indeed connect using DAC I used the SQL Management Studioand tried the following:

ADMIN:.\SQL2K5 and end up with the same error.

Dedicated adminstrator connections are not supported.

This means I am not able to connect using DAC still.

I cant post the attachment or else I would have posted the attachment.

|||There can only be ONE admin connection. If you successfully connect via "sqlcmd -A" then you will not be able to make another admin connection via sqlwb (vice versa).

Admin connection has nothing to do with regular user connection. So, it's normal that you still can connect via sqlwb. However, it will not be possible for you to open another admin connection (i.e. admin:\.sql2k5) via sqlwb if you already connect with sqlcmd.

As I have said before, you need to connect normally (without admin) when you first open up sqlwb. Once that's done, you can open a new query window (File -> New -> Database Engine Query) and connect as an admin connection.

If you still have problem, please post the entire sql log here.|||

Do you obtain this error message:

"Dedicated administrator connections are not supported. (ObjectExplorer)"

If so you try to connect the Object Explorer. Try to open a new query windows as oj told you.

|||

Thanks everyone. I seem to have connected through the cmd prompt through DAC and when I query using @.@.Servername I can see my machine name in the cmd prompt window. I am just wondering if there is a command in SQL Server 2005 that tells me whether I am connected using dedicated admin connection or that my present connection is a DAC. If so, I would appreciate if if anyone lets me know it.

Thanks

AK.

|||

The query below should return 1 row if you are connected using dedicated admin connection. It should not return any rows if you are not connected using DAC.

select * from sys.dm_exec_connections ec join sys.endpoints e on (ec.endpoint_id=e.endpoint_id) where e.name='Dedicated Admin Connection' and session_id=@.@.spid

|||

Thanks Ashvin. That did exactly confirm that I was connected using DAC. It returned one row. So my million dollar question is why cant I connect to DAC using ADMIN keyword. I tried all that have been suggested in this thread and still it says DAC connections are not supported (Object Explorer). Its a mystery!!!.

However thanks for all the suggestions.

|||

Hi,

DAC is a feature which is disabled by default. Did you enable it so far ? I made a screencast for you showing how to enable this feature. This is the second of a series which I decided to make. So have Fun !

A link with the screencasts taken so far will be on my site as I will have time for that.

use this link here in the meantime: http://www.SQLServer2005.de/ScreenCasts/Enable_DAC.htm

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

Monday, March 19, 2012

decryptbykey multiple session issue

Hi

I'm having some issues using the decryptbykey method via multiple connections. When I run the below test script simultaneously on two machines the sum function is always less then the known amount (ie 14945490 and 36382777). Does anyone know of any locking method or alternative way to sum an encrypted column?

Thanks in advance

Waz

open symmetric key HR01 decryption by password='yes'
DECLARE @.Bonus decimal
DECLARE @.Salary decimal
DECLARE @.Errors int
DECLARE @.Success int
DECLARE @.LoopCount int
SET @.Errors = 0
SET @.Success = 0
SET @.LoopCount = 0

WHILE (@.LoopCount < 40)
BEGIN

SELECT
@.Bonus = SUM(convert(float,convert(varchar(80),decryptbykey(Bonus)))),
@.Salary = SUM(convert(float,convert(varchar(80),decryptbykey(Salary))))
FROM ChallengeEmployee
WHERE ChallengeID = 5

IF(@.Bonus <> 14945490 OR @.Salary <> 36382777)
BEGIN
PRINT 'Bonus ' + CAST(@.Bonus AS varchar(80))
PRINT 'Salary ' + CAST(@.Salary AS varchar(80))
SET @.Errors = @.Errors + 1
END
ELSE
SET @.Success = @.Success + 1

SET @.LoopCount = @.LoopCount + 1

END

PRINT 'Finish'
PRINT 'Errors ' + CAST(@.Errors AS varchar(80))
PRINT 'Success ' + CAST(@.Success AS varchar(80))
close symmetric key HR01

Unfortunately binary values cannot be converted/casted back to real/float data types. This limitation was also present in SQL Server 2000 (and from the information I could find, even in earlier versions). For detailed information on allowed cast/convert operations see http://msdn2.microsoft.com/en-us/library/ms187928.aspx.

I would recommend using a different data type if possible. Another workaround would be to cast to an intermediate data type (i.e. to a string), but this will cause data loss, and I would personally recommend against it because of the data loss potential. This seems to be the case in your particular scenario.

We really appreciate your feedback.

-Raul Garcia

SDE/T

SQL Server Engine

|||

Hi Raul

Thanks for the reply.

I don't think it's a cast issue. I am actually casting to a string in my function. The problem seems to be with running over multiple connections. Running the test script on a single machine works fine. If I run the test scripts below the actual and binary values always return the correct values. Only the Encrypted ones fail when running from two separate machines. (all works fine on one connection). Maybe it's how I'm handling the keys. Could a close statement on a connection effect another connections read?

Cheers

--########################################### Setup Data ###############################################

open symmetric key HR01 decryption by password='yes'
DECLARE @.LoopCount int
DECLARE @.Bonus decimal
DECLARE @.Salary decimal
DECLARE @.EmployeeID int


CREATE TABLE TestData
(
empId int,
BonusActual decimal,
SalaryActual decimal,
BonusBinary varbinary(64),
SalaryBinary varbinary(64),
BonusEncrypt varbinary(64),
SalaryEncrypt varbinary(64)
)

SET @.EmployeeID = 1000
SET @.Bonus = 20000
SET @.Salary = 60000
SET @.LoopCount = 0
WHILE (@.LoopCount < 1000)
BEGIN
INSERT INTO TestData (empId, BonusActual, SalaryActual, BonusEncrypt,SalaryEncrypt)
VALUES (
@.EmployeeID,
@.Bonus,
@.Salary,
EncryptByKey(Key_GUID('HR01'), (CAST(@.Bonus AS varchar(80)))),
EncryptByKey(Key_GUID('HR01'), (CAST(@.Salary AS varchar(80))))
)

SET @.EmployeeID = @.EmployeeID + 1
SET @.Bonus = @.Bonus + 100
SET @.Salary = @.Salary + 500
SET @.LoopCount = @.LoopCount + 1
END

UPDATE TestData SET BonusBinary = decryptbykey(BonusEncrypt), SalaryBinary = decryptbykey(SalaryEncrypt)

close symmetric key HR01

--########################################### Verify Sums ###############################################

open symmetric key HR01 decryption by password='yes'
-- All figures should equal below (and do)
-- Bonus = 69950000
-- Salary = 309750000
SELECT
SUM(BonusActual) as 'BonusActualSum',
SUM(CAST((CAST(BonusBinary AS varchar(80)))AS decimal)) as 'BonusBinarySum',
SUM(CAST((CAST((decryptbykey(BonusEncrypt)) AS varchar(80)))AS decimal)) as 'BonusEncryptSum',
SUM(SalaryActual) as 'SalaryActualSum',
SUM(CAST((CAST(SalaryBinary AS varchar(80)))AS decimal)) as 'SalaryBinarySum',
SUM(CAST((CAST((decryptbykey(SalaryEncrypt)) AS varchar(80)))AS decimal)) as 'SalaryEncryptSum'
FROM TestData

close symmetric key HR01

--########################################### Run Tests ###############################################

open symmetric key HR01 decryption by password='yes'

DECLARE @.BonusActualSum decimal
DECLARE @.SalaryActualSum decimal
DECLARE @.BonusBinarySum decimal
DECLARE @.SalaryBinarySum decimal
DECLARE @.BonusEncryptSum decimal
DECLARE @.SalaryEncryptSum decimal
DECLARE @.ActualErrors int
DECLARE @.BinaryErrors int
DECLARE @.EncryptErrors int
DECLARE @.Success int
DECLARE @.LoopCount int
SET @.ActualErrors = 0
SET @.BinaryErrors = 0
SET @.EncryptErrors = 0
SET @.Success = 0
SET @.LoopCount = 0

WHILE (@.LoopCount < 40)
BEGIN
SELECT
@.BonusActualSum = SUM(BonusActual),
@.BonusBinarySum = SUM(CAST((CAST(BonusBinary AS varchar(80)))AS decimal)),
@.BonusEncryptSum = SUM(CAST((CAST((decryptbykey(BonusEncrypt)) AS varchar(80)))AS decimal)),
@.SalaryActualSum = SUM(SalaryActual),
@.SalaryBinarySum = SUM(CAST((CAST(SalaryBinary AS varchar(80)))AS decimal)),
@.SalaryEncryptSum = SUM(CAST((CAST((decryptbykey(SalaryEncrypt)) AS varchar(80)))AS decimal))
FROM TestData

IF(@.BonusActualSum <> 69950000 OR @.SalaryActualSum <> 309750000) SET @.ActualErrors = @.ActualErrors + 1
IF(@.BonusBinarySum <> 69950000 OR @.SalaryBinarySum <> 309750000) SET @.BinaryErrors = @.BinaryErrors + 1
IF(@.BonusEncryptSum <> 69950000 OR @.SalaryEncryptSum <> 309750000) SET @.EncryptErrors = @.EncryptErrors + 1

IF(@.BonusActualSum <> 69950000 OR @.BonusBinarySum <> 69950000 OR
@.BonusEncryptSum <> 69950000 OR @.SalaryActualSum <> 309750000 OR
@.SalaryBinarySum <> 309750000 OR @.SalaryEncryptSum <> 309750000)
BEGIN
PRINT '@.BonusActualSum ' + CAST(@.BonusActualSum AS varchar(80))
PRINT '@.BonusBinarySum ' + CAST(@.BonusBinarySum AS varchar(80))
PRINT '@.BonusEncryptSum ' + CAST(@.BonusEncryptSum AS varchar(80))
PRINT '@.SalaryActualSum ' + CAST(@.SalaryActualSum AS varchar(80))
PRINT '@.SalaryBinarySum ' + CAST(@.SalaryBinarySum AS varchar(80))
PRINT '@.SalaryEncryptSum ' + CAST(@.SalaryEncryptSum AS varchar(80))
END ELSE
SET @.Success = @.Success + 1

SET @.LoopCount = @.LoopCount + 1
END

PRINT 'Finish'
PRINT 'ActualErrors ' + CAST(@.ActualErrors AS varchar(80))
PRINT 'BinaryErrors ' + CAST(@.BinaryErrors AS varchar(80))
PRINT 'EncryptErrors ' + CAST(@.EncryptErrors AS varchar(80))
PRINT 'Success ' + CAST(@.Success AS varchar(80))

close symmetric key HR01

Results from one machine:

Finish
ActualErrors 0
BinaryErrors 0
EncryptErrors 0
Success 40

Results from two sessions of SQL Server Management Studio run simultaneously (just showing 1 of the 37):

Warning: Null value is eliminated by an aggregate or other SET operation.
@.BonusActualSum 69950000
@.BonusBinarySum 69950000
@.BonusEncryptSum 69404000
@.SalaryActualSum 309750000
@.SalaryBinarySum 309750000
@.SalaryEncryptSum 309750000

Finish
ActualErrors 0
BinaryErrors 0
EncryptErrors 37
Success 3

|||The strange thing is I cannot get this to fail on my local SQL Express. It's just failing on our development servers and production boxes. It also takes around 3 times as long to run on the high spec'd boxes. Could be an install issue....|||

Sounds unlikely it is related to the installation, but let’s not completely discard the possibility yet.I am suspecting it may be either a problem on how the key is being used or even a concurrency bug with the key ring in addition to the way the query is being cached/optimized by the server that we haven’t seen in our tests.

Let’s try to minimize the variables and see if we can get to the root problem. Can you try the following changes on your query and run them on the system that you know you can repro the problem?

--########################################### Run Tests ###############################################

open symmetric key HR01 decryption by password='yes'

-- if possible, separate the OPEN SYMMETRIC KEY from the rest of the batch

go

-- Key HR01 should be opened w/status = 1

if( (SELECT count(*) FROM sys.openkeys) = 0 )

PRINT 'Failed!!! no keys found in the key-ring'

ELSE

SELECT * FROM sys.openkeys

go

DECLARE @.BonusActualSum decimal

DECLARE @.SalaryActualSum decimal

DECLARE @.BonusBinarySum decimal

DECLARE @.SalaryBinarySum decimal

DECLARE @.BonusEncryptSum decimal

DECLARE @.SalaryEncryptSum decimal

DECLARE @.ActualErrors int

DECLARE @.BinaryErrors int

DECLARE @.EncryptErrors int

DECLARE @.Success int

DECLARE @.LoopCount int

SET @.ActualErrors = 0

SET @.BinaryErrors = 0

SET @.EncryptErrors = 0

SET @.Success = 0

SET @.LoopCount = 0

-- RG: Let's just make sure the decryptbykey values we are getting back are not null and seem like valid decimal values (hex)

SELECT decryptbykey(BonusEncrypt) as decrypted_bonus, decryptbykey(SalaryEncrypt) as decrypted_salary FROM TestData

WHILE (@.LoopCount < 40)

BEGIN

SELECT

@.BonusActualSum = SUM(BonusActual),

@.BonusBinarySum = SUM(CAST((CAST(BonusBinary AS varchar(80)))AS decimal)),

@.BonusEncryptSum = SUM(CAST((CAST((decryptbykey(BonusEncrypt)) AS varchar(80)))AS decimal)),

@.SalaryActualSum = SUM(SalaryActual),

@.SalaryBinarySum = SUM(CAST((CAST(SalaryBinary AS varchar(80)))AS decimal)),

@.SalaryEncryptSum = SUM(CAST((CAST((decryptbykey(SalaryEncrypt)) AS varchar(80)))AS decimal))

FROM TestData

-- Let's make sure no decryption call returned null

if( @.BonusEncryptSum is null OR @.SalaryEncryptSum is null )

BEGIN

PRINT 'FAILED!!! Some values are null'

SELECT @.BonusEncryptSum, @.SalaryEncryptSum, @.LoopCount

END

IF(@.BonusActualSum <> 69950000 OR @.SalaryActualSum <> 309750000) SET @.ActualErrors = @.ActualErrors + 1

IF(@.BonusBinarySum <> 69950000 OR @.SalaryBinarySum <> 309750000) SET @.BinaryErrors = @.BinaryErrors + 1

IF(@.BonusEncryptSum <> 69950000 OR @.SalaryEncryptSum <> 309750000) SET @.EncryptErrors = @.EncryptErrors + 1

IF(@.BonusActualSum <> 69950000 OR @.BonusBinarySum <> 69950000 OR

@.BonusEncryptSum <> 69950000 OR @.SalaryActualSum <> 309750000 OR

@.SalaryBinarySum <> 309750000 OR @.SalaryEncryptSum <> 309750000)

BEGIN

PRINT '@.BonusActualSum ' + CAST(@.BonusActualSum AS varchar(80))

PRINT '@.BonusBinarySum ' + CAST(@.BonusBinarySum AS varchar(80))

PRINT '@.BonusEncryptSum ' + CAST(@.BonusEncryptSum AS varchar(80))

PRINT '@.SalaryActualSum ' + CAST(@.SalaryActualSum AS varchar(80))

PRINT '@.SalaryBinarySum ' + CAST(@.SalaryBinarySum AS varchar(80))

PRINT '@.SalaryEncryptSum ' + CAST(@.SalaryEncryptSum AS varchar(80))

END ELSE

SET @.Success = @.Success + 1

SET @.LoopCount = @.LoopCount + 1

END

PRINT 'Finish'

PRINT 'ActualErrors ' + CAST(@.ActualErrors AS varchar(80))

PRINT 'BinaryErrors ' + CAST(@.BinaryErrors AS varchar(80))

PRINT 'EncryptErrors ' + CAST(@.EncryptErrors AS varchar(80))

PRINT 'Success ' + CAST(@.Success AS varchar(80))

close symmetric key HR01

Hopefully we will be able to see if the key-ring and/or decryptbykey values are returning unexpected results. For your own safety, make sure to not post any of the decrypted values from the SELECT statement, just glance through them to see if there is anything that doesn’t seem to be a valid value. You can manually verify them be casting them to a decimal in an ad-hoc query, example:

declare @.x varbinary(100)

set @.x = 0x12000001CBA70800 -- varbinary value copied from decrypted column

print cast(@.x as decimal)

Thanks a lot,

-Raul Garcia

SDE/T

SQL Server Engine

|||

Hi Raul

Thanks again for the reply. I amended my scripts (and removed excess variables) and I can still reproduce the error i.e. quite a few of the values returned from your select statement are null. I also showed the issue to the SQL Server team and they have now passed it onto Microsoft as they could not figure it out. I've included the latest script with your changes. I'm almost convinced that it's a install issue as I can run the tests without fail against my local SQL Express.

Thanks

--########################################### Description ###############################################

--The problem seems to be with running the decryptbykey function on the Company Servers
--Running the test script under the 'Run Tests' heading on a single connection will work fine
--most of the time (sometimes 1 or 2 will fail which is a concern). But running with
--the query in two windows of SQL Management Studio simultanteously will error on almost all results.
--The actual and binary values always return the correct values. But the Encrypted values will fail to sum correctly.
--This only seems to be a problem on the servers (Win2000 Server SP4 4GB RAM, 4 CPU)
--ie On local installs of SQL Express (Win XP SP2) we have increased the loop to 4000 and
--we do not have any issues and it runs 3 times as quick.

--########################################### Setup Data ###############################################

IF NOT EXISTS(SELECT * FROM sys.symmetric_keys WHERE [name] = 'TestKey')
BEGIN
CREATE SYMMETRIC KEY TestKey WITH algorithm=DES encryption BY password = 'yes'
END

open symmetric key TestKey decryption by password='yes'

DECLARE @.LoopCount int
DECLARE @.Bonus decimal
DECLARE @.EmployeeID int
CREATE TABLE TestData
(
empId int,
BonusActual decimal,
BonusBinary varbinary(64),
BonusEncrypt varbinary(64),
)

SET @.EmployeeID = 1000
SET @.Bonus = 20000
SET @.LoopCount = 0

WHILE (@.LoopCount < 1000)
BEGIN
INSERT INTO TestData (empId, BonusActual, BonusEncrypt)
VALUES (@.EmployeeID, @.Bonus, EncryptByKey(Key_GUID('TestKey'), (CAST(@.Bonus AS varchar(80)))))

SET @.EmployeeID = @.EmployeeID + 1
SET @.Bonus = @.Bonus + 100
SET @.LoopCount = @.LoopCount + 1
END

UPDATE TestData SET BonusBinary = decryptbykey(BonusEncrypt)

close symmetric key TestKey

--########################################### Verify Sums ###############################################

open symmetric key TestKey decryption by password='yes'

-- All figures should equal below
-- Bonus = 69950000
SELECT
SUM(BonusActual) as 'BonusActualSum',
SUM(CAST((CAST(BonusBinary AS varchar(80)))AS decimal)) as 'BonusBinarySum',
SUM(CAST((CAST((decryptbykey(BonusEncrypt)) AS varchar(80)))AS decimal)) as 'BonusEncryptSum'
FROM TestData

close symmetric key TestKey

--########################################### Run Tests ###############################################

open symmetric key TestKey decryption by password='yes'

go

-- Key HR01 should be opened w/status = 1

if( (SELECT count(*) FROM sys.openkeys) = 0 )
PRINT 'Failed!!! no keys found in the key-ring'
ELSE
SELECT * FROM sys.openkeys

go

DECLARE @.BonusActualSum decimal
DECLARE @.BonusBinarySum decimal
DECLARE @.BonusEncryptSum decimal
DECLARE @.ActualErrors int
DECLARE @.BinaryErrors int
DECLARE @.EncryptErrors int
DECLARE @.Success int
DECLARE @.LoopCount int

SET @.ActualErrors = 0
SET @.BinaryErrors = 0
SET @.EncryptErrors = 0
SET @.Success = 0
SET @.LoopCount = 0

-- RG: Let's just make sure the decryptbykey values we are getting
--back are not null and seem like valid decimal values (hex)

SELECT decryptbykey(BonusEncrypt) as decrypted_bonus
FROM TestData

WHILE (@.LoopCount < 40)
BEGIN
SELECT
@.BonusActualSum = SUM(BonusActual),
@.BonusBinarySum = SUM(CAST((CAST(BonusBinary AS varchar(80)))AS decimal)),
@.BonusEncryptSum = SUM(CAST((CAST((decryptbykey(BonusEncrypt)) AS varchar(80)))AS decimal))
FROM TestData

-- Let's make sure no decryption call returned null
if(@.BonusEncryptSum is null)
BEGIN
PRINT 'FAILED!!! Some values are null'
SELECT @.BonusEncryptSum, @.LoopCount
END

IF(@.BonusActualSum <> 69950000) SET @.ActualErrors = @.ActualErrors + 1
IF(@.BonusBinarySum <> 69950000) SET @.BinaryErrors = @.BinaryErrors + 1
IF(@.BonusEncryptSum <> 69950000) SET @.EncryptErrors = @.EncryptErrors + 1

IF(@.BonusActualSum <> 69950000 OR
@.BonusBinarySum <> 69950000 OR
@.BonusEncryptSum <> 69950000)
BEGIN
PRINT '@.BonusActualSum ' + CAST(@.BonusActualSum AS varchar(80))
PRINT '@.BonusBinarySum ' + CAST(@.BonusBinarySum AS varchar(80))
PRINT '@.BonusEncryptSum ' + CAST(@.BonusEncryptSum AS varchar(80))
END
ELSE
SET @.Success = @.Success + 1
SET @.LoopCount = @.LoopCount + 1
SET @.BonusEncryptSum = null
END

PRINT 'Finish'
PRINT 'ActualErrors ' + CAST(@.ActualErrors AS varchar(80))
PRINT 'BinaryErrors ' + CAST(@.BinaryErrors AS varchar(80))
PRINT 'EncryptErrors ' + CAST(@.EncryptErrors AS varchar(80))
PRINT 'Success ' + CAST(@.Success AS varchar(80))

close symmetric key TestKey

|||

This is really strange. Just to make sure that it is decryptbykey usage the one causing problems, can you try this change in the script on the real servers:

SELECT BonusEncrypt , decryptbykey(BonusEncrypt) as decrypted_bonus
FROM TestData

If it is decryptbykey is the one failing, we should see a valid encrypted value (the encrypted value should start with the same sequence, the key GUID on all rows and be of the same length) in the first column and null in the second one. If the first column shows any null then it also fails during the encryptbykey function.

After this test, can you try to change the script to add encryption by a certificate to TestKey and use decryptByKeyAutoCert? The way the decryptByKeyAutoCert handles the key ring may help on this particular case as a workaround; as I have never seen this behavior before, I am not sure if it will really work but it may be worth to give it a try:

OPEN SYMMETRIC KEY TestKey DECRYPTION BY PASSWORD = 'yes'

ALTER SYMMETRIC KEY TestKey ADD ENCRYPTION BY CERTIFICATE TestCert

CLOSE SYMMETRIC KEY TestKey

go

And on the test script, remove the OPEN SYMMETRIC KEY statement and use decryptbykeyautocert( cert_id('TestCert'), N'yes', BonusEncrypt) instead of the regular decryptbykey function.

I will also need to investigate more on this one, but any additional information I can get will help. I will also appreciate if you can test an algorithm different than DES. For testing purposes only, can you also give it a try with RC4 and RC2 algorithms?

Thanks a lot,

-Raul Garcia

SDE/T

SQL Server Engine

|||

I ran the select with the extra column and all of the BonusEncrypt values were returned correctly. Beside them were quite a few nulls in the decrypted_bonus column.

The interesting thing was changing the encryption method to RC4 or RC2 fixed the problem. Using the certificate didn't seem to make a difference.

Thanks
Warren

|||

Based on your observations I am suspecting the problem may be related to how Windows 2000 CAPI works with DES keys (to be more specific, the parity bits). Can you please try the following two tests?

* First, try using TRIPLE_DES instead of DES, I would expect a similar behavior.

* Save some of the rows that return null for the decrypted value, close and reopen the symmetric key and then copy the encrypted value and run the following script:

declare @.x varbinary(1000)

set @.x = -- Copy the encrypted value here

select datalength(@.x), decryptbykey( @.x )

go

Run this select statement a few times (reopen the key), it should always fail the same way (return null), the first column (datalength) is only to see if the encrypted data length seems correct (should always be the same). I would also expect that the select statement above works consistently with the rows that returned as not-null.

In the meantime I will continue investigating on my own environment. Thanks a lot.

-Raul Garcia

SDE/T

SQL Server Engine

|||

Hi Raul

I tried the TRIPLE_DES and it works fine. Just to make sure I repeated the test several times with both encryption methods and DES always failed and TRIPLE_DES never fails.

Also I couldn't get the script you sent to fail. So it only seems to be when reading from a table. Just to make sure I ran this script simultaneously in two windows without any errors:

OPEN SYMMETRIC KEY TestKey decryption by password='yes'

DECLARE @.LoopCount int
DECLARE @.x varbinary(1000)
DECLARE @.y varbinary(1000)
DECLARE @.z varchar(20)
SET @.LoopCount = 0
WHILE (@.LoopCount < 100000)
BEGIN
SET @.x = 0x0070D1427D69FA4BBC7EE4C3A031DCFE01000000C9E733BEA6BD461A28B9F8522280F0644CB68BE940D5E8AE
SET @.LoopCount = @.LoopCount + 1
SET @.y = decryptbykey( @.x )
SET @.z = CAST(@.y AS varchar(20))
IF @.y IS NULL OR @.z <> '20400' PRINT CAST(datalength(@.x) AS varchar(20)) + ' ' + @.z
SET @.y = NULL
SET @.z = NULL
END

CLOSE SYMMETRIC KEY TestKey

|||

I am working on this case with the premier support group, we will continue via premier support.

Thanks,

-Raul Garcia

SDE/T

SQL Server Engine

|||

As I mentioned on my last post, the premier support engineers are working on this case with the customer, but they already figured out that the root of the problem is a bug in Windows 2000 CryptoAPI that only happens when using DES keys.

To prevent anyone else to hit the same problem, I decided to update this thread. We strongly suggest updating to Windows 2003 server products, or if you still need to continue using Windows 2000 use a different algorithm, we strongly recommend using TRIPLE_DES keys when using Windows 2000.

Thanks a lot, and kudos to the Premier Support team for their great work and help on this case!

-Raul Garcia
SDE/T
SQL Server Engine

Decode in SQL Server

Hi

I have oracle statement and I want to translate it in SQL Server:

select DECODE(count(bid_Vendor), 1, NULL, COUNT(BID_VENDOR))
from bid_total

I tried it this way:
Select case(count(bid_vendor) when 1 then null else count(bid_vendor)end) as cs from bid_total

It gave me error i.e.

Incorrect syntax near the keyword 'when'Select CASE count(bid_vendor)
WHEN 1 then null
ELSE count(bid_vendor)
END as cs
FROM bid_total-PatP

Sunday, March 11, 2012

Decode funktion

Hi!

I have a question about the "Decode" funktion. is it only avaiable in Oracle? The reason for my question is that I need to SELECT a colum in a table based on a int value. So if the uservalue is lower then that take that colum, lower then that take colum...etc.

Can I use decode? or/and is there better funktion (I'm using MS SQL 2005)

Thanks in advance

Mark

MSSQL does not have a DECODE function and I'm not familiar with a function that performs the same functionality.

One way to implement what you want is to use the case statement. Example.

Select

Case when @.UserInput between 1 and 5 then 'A'

Case when @.UserInput between 6 and 10 then 'B'

Case else 'C'

end as MyColumn

From

MyTable

I believe Oracle also supports the case syntax, so if you modify your

SQL statement inside Oracle and it works, then it should easily migrate

over to MSSQL.

Larry Pope|||Thanks a lot, I think that will work just fine!

I have sub question then, is it possible to use the a case in a loop? Because I have a table where I don't know the values of the intervals.

Thanks, Mark|||I'm not entirely sure what you are trying to accomplish. I kind

of have an idea but before I offer a suggestion, I'd like to get a

little more detail.

Could you provide some background and a quick example?

Larry Pope|||yeah, its

kinda fuzzy my questions.<br><br>I have a table with

"over", "under", and "price". this table contains intervals

over under Price
0 100 400
101 250 600
251 357 800

And

continues like that. I have to get the user value and run through the

table to find the right price (between over and under), and use the price value for a calculation

in my query. Did that make any sense at all ? :)|||No, that makes sense now. You want to return the correct price

for a given quantity. At least that's my take on it. I'm

curious, Is this for a SSIS package or for some transactional

system?

The following SQL statement would be good if your issuing the statement for a transactional system one at a time.

Select

Price

From

PriceTable

Where

@.UserValue Between Over and Under

You will of course need to build logic for when the input parameter

doesn't match any records, or worse yet there is bad data and returns

multiple records.

If your trying to do the lookup process in bulk, there are other ways (conditional joins) that might perform better.

Larry Pope|||I should have seen that myself, but I didn't so thanks :) No, its a online cargo price calculater. There are many values and options involved in cargo, so it makes some bad bad statements.

I have to see about the performance... I hope it will work, otherwise I'll just have to optimize along the way. I'm so lucky this is a pilot project, so they just want it to work.

Thanks again, Mark

Saturday, February 25, 2012

DEC ODBC

Hi
I've got a DTS package that connects to a database on a DEC Vax, but I don't
have the ODBC driver. Anyone know where I can get a DEC ODBC Driver?
Thanks
JohnIt depends on what database. The following link lists ODBC
driver vendors:
http://www.sqlsummit.com/ODBCVend.htm
-Sue
On Thu, 11 Mar 2004 08:11:09 -0800, John Bandettini
<anonymous@.discussions.microsoft.com> wrote:

>Hi
>I've got a DTS package that connects to a database on a DEC Vax, but I don'
t have the ODBC driver. Anyone know where I can get a DEC ODBC Driver?
>Thanks
>John

Friday, February 17, 2012

debug via Enterprise Manager

Hi
I wonder if there is a trick I can use to debug what was changed in my
database (mssql2000).
The idea maybe sound stupid but my boss have got old console application
which is doing some changes in database (only in data in tables rather. I
have no code for that application and we are wondering where this appl.
writes - what changes and so on.
Any idea?
DarekHi
You may want to use SQL Profiler to see what statements the application is
sending to the database server.
John
"Dariusz Tomon" <d.tomon@.mazars.pl> wrote in message
news:eIJBW$aKGHA.216@.TK2MSFTNGP15.phx.gbl...
> Hi
> I wonder if there is a trick I can use to debug what was changed in my
> database (mssql2000).
> The idea maybe sound stupid but my boss have got old console application
> which is doing some changes in database (only in data in tables rather.
> I have no code for that application and we are wondering where this appl.
> writes - what changes and so on.
> Any idea?
> Darek
>

debug via Enterprise Manager

Hi
I wonder if there is a trick I can use to debug what was changed in my
database (mssql2000).
The idea maybe sound stupid but my boss have got old console application
which is doing some changes in database (only in data in tables rather. I
have no code for that application and we are wondering where this appl.
writes - what changes and so on.
Any idea?
Darek
Hi
You may want to use SQL Profiler to see what statements the application is
sending to the database server.
John
"Dariusz Tomon" <d.tomon@.mazars.pl> wrote in message
news:eIJBW$aKGHA.216@.TK2MSFTNGP15.phx.gbl...
> Hi
> I wonder if there is a trick I can use to debug what was changed in my
> database (mssql2000).
> The idea maybe sound stupid but my boss have got old console application
> which is doing some changes in database (only in data in tables rather.
> I have no code for that application and we are wondering where this appl.
> writes - what changes and so on.
> Any idea?
> Darek
>