Showing posts with label contains. Show all posts
Showing posts with label contains. Show all posts

Wednesday, March 21, 2012

Problem with a query

Hi, I have a problem with SQL Server 2000:

this query, who works on the table "Flussi_Rivendite" which contains more or less 700.000 rows, doesn't work speedly:

SQL = "SELECT SUM(Quantità) AS Quantità " _

& "FROM Flussi_Rivendite WHERE " _

& "DataFlusso BETWEEN 20070101 AND 20071031 AND " _

& "ID_AnagraficaRivendita IN " _

& "(SELECT AnagraficaRivendite.ID_AnagraficaRivendita FROM AnagraficaRivendite WHERE " _

& "AnagraficaRivendite.ID_Agente=" & dTable_Agenti.Rows(x)("ID_Agente") & ")"

The problem is in last part of query:

& "ID_AnagraficaRivendita IN " _

& "(SELECT AnagraficaRivendite.ID_AnagraficaRivendita FROM AnagraficaRivendite WHERE " _

& "AnagraficaRivendite.ID_Agente=" & dTable_Agenti.Rows(x)("ID_Agente") & ")"

ID_Agente is a foreign key of another table ("AnagraficaRivendite" which contains 60.000 rows)

I have seen I can improve "waiting time" of this query if I add "ID_Agente" field at table Flussi_Rivendite, so I can transform initial query in other query simpler:

SQL = "SELECT SUM(Quantità) AS Quantità " _

& "FROM Flussi_Rivendite WHERE " _

& "DataFlusso BETWEEN 20070101 AND 20071031 AND " _

& "ID_Agente=" & dTable_Agenti.Rows(x)("ID_Agente")

I would ask you if it is correct to add column ID_Agente on the table Flussi_Rivendite. Until today I have always avoided to do this, I have always filtered my table by query like: "....IN (SELECT FIELDS FROM TABLE WHERE ecc...)".

But now, these tables have many many records and I have found only this solution to improve the query (like I have just said, adding external key "ID_Agente" directly on table "Flussi_Rivendite". Sorry for my english, I hope someone can suggest something me ;)

Hi Maurodii

I like the table names -- some beautiful language!

Did you try:

"SELECT SUM(Flussi_Rivendite .Quantità) AS Quantità " _& "FROM Flussi_Rivendite, AnagraficaRivendite WHERE " _& " Flussi_Rivendite.DataFlusso BETWEEN 20070101 AND 20071031 AND " _

& " Flussi_Rivendite.ID_AnagraficaRivendita = AnagraficaRivendite. ID_AnagraficaRivendita " _

& "AnagraficaRivendite.ID_Agente=" & dTable_Agenti.Rows(x)("ID_Agente") & ")"

Hope this helps and Good Luck!

Fouwaaz

|||

IN can be a performance killer. Look into using EXISTS instead of IN.

|||

Hello, I have tried this but the performance is the same, unfortunately :(

SQL = "SELECT SUM(Flussi_Rivendite.Quantita) AS Quantita " _

& "FROM Flussi_Rivendite, AnagraficaRivendite WHERE " _

& "Flussi_Rivendite.DataFlusso BETWEEN 20070101 AND 20071031 AND " _

& "Flussi_Rivendite.ID_AnagraficaRivendita = AnagraficaRivendite.ID_AnagraficaRivendita AND " _

& "AnagraficaRivendite.ID_Agente=" & dTable_Agenti.Rows(x)("ID_Agente")

Dear ndinakar, may you post me how you suggest me to do with the clause EXISTS? I have tried it, but I didn't make it :(

I remember you that my target is don't preserve column "ID_Agente" in table Flussi_Rivendite.

Thank you

|||

Try running the query directly in Query Analyzer or Management Studio and see how long its taking. Also I would recommend using >= and <= instead of using BETWEEN.

SELECTSUM(Flussi_Rivendite.Quantita)AS Quantita

FROM Flussi_Rivendite, AnagraficaRivendite

WHERE Flussi_Rivendite.DataFlusso>='20070101'AND Flussi_Rivendite.DataFlusso<='20071031'

AND Flussi_Rivendite.ID_AnagraficaRivendita= AnagraficaRivendite.ID_AnagraficaRivendita

AND AnagraficaRivendite.ID_Agente=<somevalue>

|||

I have changed clause Between like you suggested me but performance doesn't improve. Moreover, I have tried to run both query in Query Analyzer, I post here results:

Query N.1

SELECT SUM(Flussi_Rivendite.Quantità) AS Quantità
FROM Flussi_Rivendite, AnagraficaRivendite WHERE
Flussi_Rivendite.DataFlusso>=20070901 AND Flussi_Rivendite.DataFlusso<=20070931 AND
Flussi_Rivendite.ID_AnagraficaRivendita = AnagraficaRivendite.ID_AnagraficaRivendita AND
AnagraficaRivendite.ID_Agente=1

Flussi_Rivendite: Costs: 67% Anagrafica_Rivendite: Costs: 300%

Query N.2

SELECT SUM(Quantità) AS Quantità
FROM Flussi_Rivendite WHERE
DataFlusso BETWEEN 20070901 AND 20070931 AND
ID_Agente=1

Flussi_Rivendite: Costs: 0% Anagrafica_Rivendite: Costs: 0%

In my opinion when I directly filter ID_Agente in the same table (Query n.2) is best solution for me, also if database's structure will be a little more complicated. But it is too faster then Query n.1

|||

Do you have any indexes on DataFlusso column? or on AnagraficaRivendite.ID_Agente column? Having proper indexes is important for faster data retrieval otherwise SQL Server has to scan your entire table to get to the rows and then perform the computation.

|||

IMPORTANT IMPROVEMENT!!!!

I have built a new index like you suggested me in table Flussi_Rivendite: DataFlusso, ID_AnagragraficaRivendite, ID_Agente.

Now waiting time is pull down until 6/7 seconds!!!! It is good, also if with my alternative procedure waiting time it was 3/4 seconds. Thank you again, next monday I will come back in the office and I'll try it better (now I am working from my home by Remote Desktop and it's not easy...).

Have a good week end!!

ps: If you some indication to built/edit better this new index please tell me ;)

|||

Build this index on AnagraficaRivendite : ID_Agente, ID_AnagraficaRivendita

|||

Motley:

Build this index on AnagraficaRivendite : ID_Agente, ID_AnagraficaRivendita

I've already created.

Please note that if I change range of DataFlusso (for es. 20060101 and 20071031) waiting time increases again, but I think it's normal because so I'm asking for more records. I think I need a newer and faster processor... ;) or not?

|||

I think this is best solution if I don't add a column ID_Agente to table Flussi_Rivendite:

SELECT SUM(dbo.Flussi_Rivendite.Quantità) AS Quantità
FROM dbo.Flussi_Rivendite INNER JOIN
dbo.AnagraficaRivendite ON dbo.Flussi_Rivendite.ID_AnagraficaRivendita = dbo.AnagraficaRivendite.ID_AnagraficaRivendita
WHERE (dbo.Flussi_Rivendite.DataFlusso >= 20070101) AND (dbo.Flussi_Rivendite.DataFlusso <= 20070131) AND
(dbo.AnagraficaRivendite.ID_Agente = 2)

ByeSmile

Problem with a query

I have 3 tables Workers, Event and Worker_Event_Persmissions.The workers table contains a list of workers, the events table contains a list of events – exam, assessments and tests, and finally the worker_event_permissions contains details about the permissions for each worker whether they can view, amend or check.

I want to create a select query that shows all events for each worker and the permissions assigned.I would like the role and event to be displayed even if there are no workerevent permissions setup.

Can anyone help?

Workers

RoleDescription

TeaTeacher

TutTutor

Event

TypeDescription

ExExam

AsmAssessment

TeTest

Worker_Event_Permissions

Role_TypeEvent_TypeViewAmendCheck

TeaExYNY

TeaAsmNNY

TutTeYYY

Query

TypeRoleViewAmendCheck

ExamTeacherYNY

AssessmentTeacherNNY

TestTeacherNULLNULLNULL

ExamTutorNULLNULLNULL

AssessmentTutorNULLNULLNULL

TestTutorYYY

here You go..

Code Snippet

Create Table #workers (

[Role] Varchar(100) ,

[Description] Varchar(100)

);

Insert Into #workers Values('Tea','Teacher');

Insert Into #workers Values('Tut','Tutor');

Create Table #event (

[Type] Varchar(100) ,

[Description] Varchar(100)

);

Insert Into #event Values('Ex','Exam');

Insert Into #event Values('Asm','Assessment');

Insert Into #event Values('Te','Test');

Create Table #worker_event_permissions (

[Role_Type] Varchar(100) ,

[Event_Type] Varchar(100) ,

[View] Varchar(100) ,

[Amend] Varchar(100) ,

[Check] Varchar(100)

);

Insert Into #worker_event_permissions Values('Tea','Ex','Y','N','Y');

Insert Into #worker_event_permissions Values('Tea','Asm','N','N','Y');

Insert Into #worker_event_permissions Values('Tut','Te','Y','Y','Y');

Query

Select WD,WD,[View],[Amend],[Check] From

(

Select

W.Role WR, E.Type ET,

W.[Description] WD,E.[Description]ED

from

#workers W Cross Join #event E

) as Data

Left Outer Join

#worker_event_permissions WEP

On WEP.Role_Type = Data.WR And WEP.Event_Type=Data.ET

Problem with a linked Server

Ok, it may be simple, but i really dont find it! lol

so, We have a AS400, wich contains live data from our stores. Here we work on SQL Server, but we need access to the live data. So we want to transfer data every night from the 400 to one of our databases in SQL Server. So we made a Linked Server, wich works fine. But there is, somewhere, a buffer that wont let us transfer a big load of data at the same time. for example

SELECT * FROM OpenQuery(MyLinkServer, 'SELECT * FROM SYNTAXPF."NU.POHDR"')
this returns 862 rows.

SELECT * FROM OpenQuery(MyLinkServer, 'SELECT PHDIVX FROM SYNTAXPF."NU.POHDR"')
this returns all 1719 rows from the table.

So there must be a buffer between the 2 servers, but i cant seem to fin how to remove it, or at least make it bigger. I had to create a stored wich 5 tables from the 400 and put the information into 1 table in SQL Server, but there is an awsome load of records in these 5 tables, so i was forced to make a cursor wich loops on suppliers, and this takes aver a half hour to execute, since we have close to 5000 suppliers, but we only receive stock from like 2-3% of them, so my loop execute a heck of a lot of select statement that are actually useless, and that takes a lot of time to execute. i would prefer to remove that stupid buffer, and simply make one select that will retur all the rows from the 5 tables. it would take like 3 minutes to execute...

Is this question related to Integration Services? If you are using Integration Services to transfer data, you don't need to use Linked Server, you can connect SSIS to AS400 directly and move data to SQL Server.

If this is not related to SSIS (as you did not mention SSIS in the question), please repost it to correct forum, I think SQL Data Access is the best for Linked Server questions: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=87&SiteID=1

|||well, it is not related to SSIS, but, I wont repost somwhere else as I found the solution bu myself. It was an option i havent seen at first, abd now it works well. thanks anyway

Problem with [Left] in SQL Server 2005?

We have a table that contains a column named "Left". (Yea, I know, this was a bad idea - but it is not within my power to change it.)

Our stored procedures access it using [Left] without any problems in Sql Server 2000 and Sql Server Express Edition. HOWEVER, it does NOT work with SQL Server 2005. It generates the error: Column 'Left' is read-only.

Has anyone seen this? Is there a problem with SQL Server 2005 and reserved words using [ ] notation?

Thanks!

This is not a problem with the identifier (quoted or bracketed). The error message indicates that you are trying to modify the column using a query expression (CTE, view or derived table) and it is seen as read-only. Can you post a simple repro showing the problem? Or can you post the statement that is generating the error message.|||

We just tried running the stored procedure directly, and it works fine as well. So this must be a problem with ADO? Does that mean that I should be posting this question elsewhere? (Again, it works fine if we just reset the connection string to point to the database in SQL Server 2000 or SQL Server Express.)

This is a HUGE application that uses a form of the MS data block so it may be challenging (i.e. time consuming) to pull together a reasonably sized repro. But I'll see what I can get approval for ...

|||It could be something wrong in the client side. The client might be trying to update the query result (from query or view or SP). For example, you could be using wrong cursor type in the client code that might make the application think that a result is updateable. You could run a SQL Profiler trace to determine the statement from the client that is causing the error on the server. And there is no need to post the repro involving the client and the exact code. You should try to reproduce the problem independently using smaller set of tables and sample data. This is often the best way to isolate and understand the problem.|||

Found the problem. It had nothing to do with the [Left] actually. The stored procedure was doing a Union. The union seems to produce an updatable dataset in SQL Server 2000 and in SQL Server Express but NOT in Sql Server 2005.

Interesting ...

problem with # sign

I have a stored proc that takes a parameter and finds the correct row.
Simple and easy. Unfortunately the data contains various symbols such as #
and -. When I run the proc and try to pass a value that contains a symbol I
get an error. The sp works fine when there are no symbols. Any
suggestions?
Laura KOh and here is the sp.
@.ProductCode nvarchar (5)
AS
SELECT pc.strcolorID, p.intproductID
FROM dbo.tblProducts p join tblJctProductsColors pc
On p.IntProductID=pc.intProductID
WHERE strProductCode = @.ProductCode
Simple sp. but wont work with symbols. I ran the proc with #322 and I get
an error. Sorry I am a newbie. Any help appreciated.
Thanks
Laura K
"Laura K" <klkazanAT@.ATcharter.net> wrote in message
news:%23du%23BpJoFHA.3316@.TK2MSFTNGP14.phx.gbl...
>I have a stored proc that takes a parameter and finds the correct row.
>Simple and easy. Unfortunately the data contains various symbols such as #
>and -. When I run the proc and try to pass a value that contains a symbol
>I get an error. The sp works fine when there are no symbols. Any
>suggestions?
> Laura K
>|||What about the table structures? You don't say what the column definitions
are.
"Laura K" <klkazanAT@.ATcharter.net> wrote in message
news:u1OSNtJoFHA.2472@.TK2MSFTNGP15.phx.gbl...
> Oh and here is the sp.
> @.ProductCode nvarchar (5)
> AS
>
> SELECT pc.strcolorID, p.intproductID
> FROM dbo.tblProducts p join tblJctProductsColors pc
> On p.IntProductID=pc.intProductID
> WHERE strProductCode = @.ProductCode
> Simple sp. but wont work with symbols. I ran the proc with #322 and I get
> an error. Sorry I am a newbie. Any help appreciated.
> Thanks
> Laura K
> "Laura K" <klkazanAT@.ATcharter.net> wrote in message
> news:%23du%23BpJoFHA.3316@.TK2MSFTNGP14.phx.gbl...
>|||Hi
You may want to put checks into the client to stop data being passed that
will not be valid. You do not say what the error is, as #322 I would expect
no rows to be returned rather than any specific error.
John
"Laura K" <klkazanAT@.ATcharter.net> wrote in message
news:u1OSNtJoFHA.2472@.TK2MSFTNGP15.phx.gbl...
> Oh and here is the sp.
> @.ProductCode nvarchar (5)
> AS
>
> SELECT pc.strcolorID, p.intproductID
> FROM dbo.tblProducts p join tblJctProductsColors pc
> On p.IntProductID=pc.intProductID
> WHERE strProductCode = @.ProductCode
> Simple sp. but wont work with symbols. I ran the proc with #322 and I get
> an error. Sorry I am a newbie. Any help appreciated.
> Thanks
> Laura K
> "Laura K" <klkazanAT@.ATcharter.net> wrote in message
> news:%23du%23BpJoFHA.3316@.TK2MSFTNGP14.phx.gbl...
>|||I get specific errors.
When I use 86-283 there error is
Line 1: Incorrect syntax near '-'
I also have spaces in some of the codes so when I use
spGetProductColor TUK Elvis W
Line 1: Incorrect syntax near 'Elvis'.
Upon closer inspection I have no problems with the # sign thus making the
title of my post obsolete. I do however have problems with the - and
spaces.
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:OnpT6tLoFHA.632@.tk2msftngp13.phx.gbl...
> Hi
> You may want to put checks into the client to stop data being passed that
> will not be valid. You do not say what the error is, as #322 I would
> expect no rows to be returned rather than any specific error.
> John
> "Laura K" <klkazanAT@.ATcharter.net> wrote in message
> news:u1OSNtJoFHA.2472@.TK2MSFTNGP15.phx.gbl...
>|||The column in question is a brandcode which may include numbers, letters or
what have you depending on the manufactures usage. The datatype is
nvarchar. It is not related to any other table. The table is related by the
productID to many other tables.
Not sure if this is what you are asking.
Laura
"Colin Dawson" <newsgroups@.cjdawson.com> wrote in message
news:5rDLe.88549$G8.69248@.text.news.blueyonder.co.uk...
> What about the table structures? You don't say what the column
> definitions are.
> "Laura K" <klkazanAT@.ATcharter.net> wrote in message
> news:u1OSNtJoFHA.2472@.TK2MSFTNGP15.phx.gbl...
>|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.|||Laura,
try
exec spGetProductColor 'TUK Elvis W'
and see if that fixes it.
Stu|||It takes care of the error but now it returns nothing. However when I put
quotes around a value that has no spaces or dashes it still returns a color.
Laura
"Stu" <stuart.ainsworth@.gmail.com> wrote in message
news:1124043325.349594.239730@.o13g2000cwo.googlegroups.com...
> Laura,
> try
> exec spGetProductColor 'TUK Elvis W'
> and see if that fixes it.
> Stu
>|||Excuse the fact that I am new at this but let me know how to post DDL.
"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1124041314.536726.261720@.f14g2000cwb.googlegroups.com...
> Please post DDL, so that people do not have to guess what the keys,
> constraints, Declarative Referential Integrity, data types, etc. in
> your schema are. Sample data is also a good idea, along with clear
> specifications. It is very hard to debug code when you do not let us
> see it.
>

Tuesday, March 20, 2012

Problem with " , " and " "

I'm programming under VB, and I have a connection to a MSSQL Server 2000 database. How can I make a query work when a string contains "," and "'"? All I could think about is changing all querys to stored procedures. Is there any special character I could use to tell the server to include the coma as part of the string?whether you use stored procedures or straight sql instructions from a VB client, you still need to pass parameters and if you need to pass a string parameter that contains a single quote (') insert another quote just next to it and it should be fine. As for commas, a string parameter containing a comma and delimited by two single quotes should work fine.

try in QA:

create table #temp(field1 varchar(500))
insert into #temp(field1) values ('test1''')
insert into #temp(field1) values ('test2 ,')
select * from #temp
drop table #temp|||...but use stored procedures anyway...|||is it nececessary to user storedprocedures for data inserting?
cant we use

sSql = "insert into tablename values (" & var1 & "," & var2 & ")"
dbConn.Execute sSql

cud u pl tell, if thers ne advantage in using sp for data insertion|||Using an sp for data insertion can have the advantage of shielding the db layout from applications, so applications may not have to be modified, recompiled and distributed if changes are made. Some database administrators like to know all the update/insert statements that could be executed so they can tune the database. It might also help seperating business logic from your applications.

I'm sure there are more, but these are the ones I can come up with.

One thing I haven't mentioned is that the company you work for may have chosen for one type of approach (having all in vb or all in sp), which sort of overrules advantage/disadvantage.|||apart from separating the business logic from applications, will there be an improved performance for large insert/update statements while using an sp

i.e, for an insert statement like

sSql = "insert into table1(field1,field2,....fieldn) values ("
& val1 & "," & val2 & "," .... & "," & valn & ")"
dbConn.Execute sSql

pl post ur comments|||I'm programming under VB, and I have a connection to a MSSQL Server 2000 database. How can I make a query work when a string contains "," and "'"? All I could think about is changing all querys to stored procedures. Is there any special character I could use to tell the server to include the coma as part of the string?

you can use this code to sole ur Problem

Pvar_DataBase.Execute "insert into " & TablName _
& "(Filed01,Filed02)" _
& " Values('" & value01 & "','" & Single_Qute(Value02) & "')"

Public Static Function Single_Qute(String_Value As String) As String
Single_Qute= Replace(String_Value, "'", "''")
Single_Qute= Replace(String_Value, ",", "''")
End Function

If u have any problem

send me to
tgamil@.egysoft-it.com

Best Regards

Tarek Gamil

Saturday, February 25, 2012

Problem using sp_attach_db with an encypted file system

I want to run a copy of our Sql2000 production database on my WinXP
laptop for development. Because this database contains sensitive
information and the laptop cannot be physically secured, I have
enabled File Encryption on the project directory to protect the
database in the event that someone steals the laptop. To set up a
development environment I installed Sql2000 personal edition, and
disconnected the production database with:
EXEC sp_detach_db @.dbname ='myDB'
I then copied the mdf and log files to the encrypted directory on the
laptop and attempted to attach with:
EXEC sp_attach_db @.dbname = N'myDB',
@.filename1 = N'C:\Projects\Data.mdf',
@.filename2 = N'C:\Projects\Log.ldf'
This failed with the error message: "Device activation error. The
physical file name 'C:\Projects\Data.mdf' may be incorrect". This was
freaking me out, because the exact same command worked fine on the
production server to reattach the database. After some trial and
error, I removed file encryption on the mdf and ldf file and the
database attached without any problem.
So my questions is, is this a known problem and is it possible to have
file encryption on an SQL database?Hi
Are you using "Windows 2000 Encrypted File System option". If yes then you
have to follow this way.
1. Uncheck the File encryption
2. Attach the database using SP_ATTACH_DB
3. Stop SQL Server service
4. Login as the user SQL server service starts
5. Select the properties of the folder(s) in which the database files reside
using Windows Explorer.
6. Select the advanced option button and follow the prompts to encrypt the
files/folders.
7. Change the service startup account to he user you logged in (Control
panel -- services - mSSQL Server -- logon option)
7. Re-start the SQL Server service.
8. Verify the successful start-up of the instance and databases affected via
the encryption (or create databases after the fact over the encrypted
directories).
-- By any chance if you change the service startup account the database will
not start.
See the below link:-
http://www.sql-server-performance.com/ck_database_encryption.asp
Thanks
Hari
MCDBA
"Stephen Miller" <jsausten@.hotmail.com> wrote in message
news:cdb404de.0407212013.acd74aa@.posting.google.com...
> I want to run a copy of our Sql2000 production database on my WinXP
> laptop for development. Because this database contains sensitive
> information and the laptop cannot be physically secured, I have
> enabled File Encryption on the project directory to protect the
> database in the event that someone steals the laptop. To set up a
> development environment I installed Sql2000 personal edition, and
> disconnected the production database with:
> EXEC sp_detach_db @.dbname ='myDB'
> I then copied the mdf and log files to the encrypted directory on the
> laptop and attempted to attach with:
> EXEC sp_attach_db @.dbname = N'myDB',
> @.filename1 = N'C:\Projects\Data.mdf',
> @.filename2 = N'C:\Projects\Log.ldf'
> This failed with the error message: "Device activation error. The
> physical file name 'C:\Projects\Data.mdf' may be incorrect". This was
> freaking me out, because the exact same command worked fine on the
> production server to reattach the database. After some trial and
> error, I removed file encryption on the mdf and ldf file and the
> database attached without any problem.
> So my questions is, is this a known problem and is it possible to have
> file encryption on an SQL database?|||Hari,
Thanks for that, I'm now running the service MSSQLSERVER under my user
name and it works fine.
The realisation that only user who encrypted the files, can decrypt
them (and hence services running under system context cannot) solves
an off-topic problem I was having an ASP.Net application returning the
error "Failed to execute request because the App-Domain could not be
created. Error: 0x80070005 Access is denied." when it attempts to load
an encrypted aspx page.
Thanks,
Stephen
"Hari Prasad" <hari_prasad_k@.hotmail.com> wrote in message news:<ujGc6p6bEHA.2880@.TK2MSFTNGP12.phx.gbl>...
> Hi
> Are you using "Windows 2000 Encrypted File System option". If yes then you
> have to follow this way.
> 1. Uncheck the File encryption
> 2. Attach the database using SP_ATTACH_DB
> 3. Stop SQL Server service
> 4. Login as the user SQL server service starts
> 5. Select the properties of the folder(s) in which the database files reside
> using Windows Explorer.
> 6. Select the advanced option button and follow the prompts to encrypt the
> files/folders.
> 7. Change the service startup account to he user you logged in (Control
> panel -- services - mSSQL Server -- logon option)
> 7. Re-start the SQL Server service.
> 8. Verify the successful start-up of the instance and databases affected via
> the encryption (or create databases after the fact over the encrypted
> directories).
> -- By any chance if you change the service startup account the database will
> not start.
> See the below link:-
> http://www.sql-server-performance.com/ck_database_encryption.asp
> Thanks
> Hari
> MCDBA
>
> "Stephen Miller" <jsausten@.hotmail.com> wrote in message
> news:cdb404de.0407212013.acd74aa@.posting.google.com...
> > I want to run a copy of our Sql2000 production database on my WinXP
> > laptop for development. Because this database contains sensitive
> > information and the laptop cannot be physically secured, I have
> > enabled File Encryption on the project directory to protect the
> > database in the event that someone steals the laptop. To set up a
> > development environment I installed Sql2000 personal edition, and
> > disconnected the production database with:
> >
> > EXEC sp_detach_db @.dbname ='myDB'
> >
> > I then copied the mdf and log files to the encrypted directory on the
> > laptop and attempted to attach with:
> >
> > EXEC sp_attach_db @.dbname = N'myDB',
> > @.filename1 = N'C:\Projects\Data.mdf',
> > @.filename2 = N'C:\Projects\Log.ldf'
> >
> > This failed with the error message: "Device activation error. The
> > physical file name 'C:\Projects\Data.mdf' may be incorrect". This was
> > freaking me out, because the exact same command worked fine on the
> > production server to reattach the database. After some trial and
> > error, I removed file encryption on the mdf and ldf file and the
> > database attached without any problem.
> >
> > So my questions is, is this a known problem and is it possible to have
> > file encryption on an SQL database?

Problem using sp_attach_db with an encypted file system

I want to run a copy of our Sql2000 production database on my WinXP
laptop for development. Because this database contains sensitive
information and the laptop cannot be physically secured, I have
enabled File Encryption on the project directory to protect the
database in the event that someone steals the laptop. To set up a
development environment I installed Sql2000 personal edition, and
disconnected the production database with:
EXEC sp_detach_db @.dbname ='myDB'
I then copied the mdf and log files to the encrypted directory on the
laptop and attempted to attach with:
EXEC sp_attach_db @.dbname = N'myDB',
@.filename1 = N'C:\Projects\Data.mdf',
@.filename2 = N'C:\Projects\Log.ldf'
This failed with the error message: "Device activation error. The
physical file name 'C:\Projects\Data.mdf' may be incorrect". This was
freaking me out, because the exact same command worked fine on the
production server to reattach the database. After some trial and
error, I removed file encryption on the mdf and ldf file and the
database attached without any problem.
So my questions is, is this a known problem and is it possible to have
file encryption on an SQL database?
Hi
Are you using "Windows 2000 Encrypted File System option". If yes then you
have to follow this way.
1. Uncheck the File encryption
2. Attach the database using SP_ATTACH_DB
3. Stop SQL Server service
4. Login as the user SQL server service starts
5. Select the properties of the folder(s) in which the database files reside
using Windows Explorer.
6. Select the advanced option button and follow the prompts to encrypt the
files/folders.
7. Change the service startup account to he user you logged in (Control
panel -- services - mSSQL Server -- logon option)
7. Re-start the SQL Server service.
8. Verify the successful start-up of the instance and databases affected via
the encryption (or create databases after the fact over the encrypted
directories).
-- By any chance if you change the service startup account the database will
not start.
See the below link:-
http://www.sql-server-performance.co...encryption.asp
Thanks
Hari
MCDBA
"Stephen Miller" <jsausten@.hotmail.com> wrote in message
news:cdb404de.0407212013.acd74aa@.posting.google.co m...
> I want to run a copy of our Sql2000 production database on my WinXP
> laptop for development. Because this database contains sensitive
> information and the laptop cannot be physically secured, I have
> enabled File Encryption on the project directory to protect the
> database in the event that someone steals the laptop. To set up a
> development environment I installed Sql2000 personal edition, and
> disconnected the production database with:
> EXEC sp_detach_db @.dbname ='myDB'
> I then copied the mdf and log files to the encrypted directory on the
> laptop and attempted to attach with:
> EXEC sp_attach_db @.dbname = N'myDB',
> @.filename1 = N'C:\Projects\Data.mdf',
> @.filename2 = N'C:\Projects\Log.ldf'
> This failed with the error message: "Device activation error. The
> physical file name 'C:\Projects\Data.mdf' may be incorrect". This was
> freaking me out, because the exact same command worked fine on the
> production server to reattach the database. After some trial and
> error, I removed file encryption on the mdf and ldf file and the
> database attached without any problem.
> So my questions is, is this a known problem and is it possible to have
> file encryption on an SQL database?
|||Hari,
Thanks for that, I'm now running the service MSSQLSERVER under my user
name and it works fine.
The realisation that only user who encrypted the files, can decrypt
them (and hence services running under system context cannot) solves
an off-topic problem I was having an ASP.Net application returning the
error "Failed to execute request because the App-Domain could not be
created. Error: 0x80070005 Access is denied." when it attempts to load
an encrypted aspx page.
Thanks,
Stephen
"Hari Prasad" <hari_prasad_k@.hotmail.com> wrote in message news:<ujGc6p6bEHA.2880@.TK2MSFTNGP12.phx.gbl>...[vbcol=seagreen]
> Hi
> Are you using "Windows 2000 Encrypted File System option". If yes then you
> have to follow this way.
> 1. Uncheck the File encryption
> 2. Attach the database using SP_ATTACH_DB
> 3. Stop SQL Server service
> 4. Login as the user SQL server service starts
> 5. Select the properties of the folder(s) in which the database files reside
> using Windows Explorer.
> 6. Select the advanced option button and follow the prompts to encrypt the
> files/folders.
> 7. Change the service startup account to he user you logged in (Control
> panel -- services - mSSQL Server -- logon option)
> 7. Re-start the SQL Server service.
> 8. Verify the successful start-up of the instance and databases affected via
> the encryption (or create databases after the fact over the encrypted
> directories).
> -- By any chance if you change the service startup account the database will
> not start.
> See the below link:-
> http://www.sql-server-performance.co...encryption.asp
> Thanks
> Hari
> MCDBA
>
> "Stephen Miller" <jsausten@.hotmail.com> wrote in message
> news:cdb404de.0407212013.acd74aa@.posting.google.co m...

Problem using sp_attach_db with an encypted file system

I want to run a copy of our Sql2000 production database on my WinXP
laptop for development. Because this database contains sensitive
information and the laptop cannot be physically secured, I have
enabled File Encryption on the project directory to protect the
database in the event that someone steals the laptop. To set up a
development environment I installed Sql2000 personal edition, and
disconnected the production database with:
EXEC sp_detach_db @.dbname ='myDB'
I then copied the mdf and log files to the encrypted directory on the
laptop and attempted to attach with:
EXEC sp_attach_db @.dbname = N'myDB',
@.filename1 = N'C:\Projects\Data.mdf',
@.filename2 = N'C:\Projects\Log.ldf'
This failed with the error message: "Device activation error. The
physical file name 'C:\Projects\Data.mdf' may be incorrect". This was
freaking me out, because the exact same command worked fine on the
production server to reattach the database. After some trial and
error, I removed file encryption on the mdf and ldf file and the
database attached without any problem.
So my questions is, is this a known problem and is it possible to have
file encryption on an SQL database?Hi
Are you using "Windows 2000 Encrypted File System option". If yes then you
have to follow this way.
1. Uncheck the File encryption
2. Attach the database using SP_ATTACH_DB
3. Stop SQL Server service
4. Login as the user SQL server service starts
5. Select the properties of the folder(s) in which the database files reside
using Windows Explorer.
6. Select the advanced option button and follow the prompts to encrypt the
files/folders.
7. Change the service startup account to he user you logged in (Control
panel -- services - mSSQL Server -- logon option)
7. Re-start the SQL Server service.
8. Verify the successful start-up of the instance and databases affected via
the encryption (or create databases after the fact over the encrypted
directories).
-- By any chance if you change the service startup account the database will
not start.
See the below link:-
http://www.sql-server-performance.c..._encryption.asp
Thanks
Hari
MCDBA
"Stephen Miller" <jsausten@.hotmail.com> wrote in message
news:cdb404de.0407212013.acd74aa@.posting.google.com...
> I want to run a copy of our Sql2000 production database on my WinXP
> laptop for development. Because this database contains sensitive
> information and the laptop cannot be physically secured, I have
> enabled File Encryption on the project directory to protect the
> database in the event that someone steals the laptop. To set up a
> development environment I installed Sql2000 personal edition, and
> disconnected the production database with:
> EXEC sp_detach_db @.dbname ='myDB'
> I then copied the mdf and log files to the encrypted directory on the
> laptop and attempted to attach with:
> EXEC sp_attach_db @.dbname = N'myDB',
> @.filename1 = N'C:\Projects\Data.mdf',
> @.filename2 = N'C:\Projects\Log.ldf'
> This failed with the error message: "Device activation error. The
> physical file name 'C:\Projects\Data.mdf' may be incorrect". This was
> freaking me out, because the exact same command worked fine on the
> production server to reattach the database. After some trial and
> error, I removed file encryption on the mdf and ldf file and the
> database attached without any problem.
> So my questions is, is this a known problem and is it possible to have
> file encryption on an SQL database?|||Hari,
Thanks for that, I'm now running the service MSSQLSERVER under my user
name and it works fine.
The realisation that only user who encrypted the files, can decrypt
them (and hence services running under system context cannot) solves
an off-topic problem I was having an ASP.Net application returning the
error "Failed to execute request because the App-Domain could not be
created. Error: 0x80070005 Access is denied." when it attempts to load
an encrypted aspx page.
Thanks,
Stephen
"Hari Prasad" <hari_prasad_k@.hotmail.com> wrote in message news:<ujGc6p6bEHA.2880@.TK2MSFTNGP
12.phx.gbl>...[vbcol=seagreen]
> Hi
> Are you using "Windows 2000 Encrypted File System option". If yes then you
> have to follow this way.
> 1. Uncheck the File encryption
> 2. Attach the database using SP_ATTACH_DB
> 3. Stop SQL Server service
> 4. Login as the user SQL server service starts
> 5. Select the properties of the folder(s) in which the database files resi
de
> using Windows Explorer.
> 6. Select the advanced option button and follow the prompts to encrypt the
> files/folders.
> 7. Change the service startup account to he user you logged in (Control
> panel -- services - mSSQL Server -- logon option)
> 7. Re-start the SQL Server service.
> 8. Verify the successful start-up of the instance and databases affected v
ia
> the encryption (or create databases after the fact over the encrypted
> directories).
> -- By any chance if you change the service startup account the database wi
ll
> not start.
> See the below link:-
> http://www.sql-server-performance.c..._encryption.asp
> Thanks
> Hari
> MCDBA
>
> "Stephen Miller" <jsausten@.hotmail.com> wrote in message
> news:cdb404de.0407212013.acd74aa@.posting.google.com...

Monday, February 20, 2012

Problem updating two tables in a transaction.

Background...
In Sql Server 2000 I have two tables T1 & T2, where T2 contains a key to T1.
I have one process P1 that deletes all the records in T2 and then T1, and
then inserts new records into T1 and then T2, all done in a transaction
(default isolation level). When complete, the P1 notifies another process P2
that it has finished, and P2 immediately loads all the data from T1 and then
T2.
Problem...
P2 occasionally fails when loading T2 because it can't find a referenced row
in the data it loaded from T1. However, on a second attempt to load both
tables it succeeds. Subsequent queries on the tables show problems.
Questions...
Is this likely to be a concurrency issue? If so, why is this happening? How
can I fix it?
One thing that might be relevant is that a foreign key constraint between T2
and T1 is not defined in the database. I have limited control over this.Rick (Rick@.nowhere.com) writes:
> In Sql Server 2000 I have two tables T1 & T2, where T2 contains a key to
> T1. I have one process P1 that deletes all the records in T2 and then
> T1, and then inserts new records into T1 and then T2, all done in a
> transaction (default isolation level). When complete, the P1 notifies
> another process P2 that it has finished, and P2 immediately loads all
> the data from T1 and then T2.
> Problem...
> P2 occasionally fails when loading T2 because it can't find a referenced
> row in the data it loaded from T1. However, on a second attempt to load
> both tables it succeeds. Subsequent queries on the tables show
> problems.
> Questions...
> Is this likely to be a concurrency issue? If so, why is this happening?
> How can I fix it?
> One thing that might be relevant is that a foreign key constraint
> between T2 and T1 is not defined in the database. I have limited control
> over this.
I'm afraid that this introduction is not enough to say anything for sure.
Seeing the code would have helped?
Of course, the missing FK constraint is not good, but as long as you know
that the data you insert is consistent, it is not a problem. And, anyway,
if you were to INSERT data into T2 where the key to T1 is missing, it
should keep on failing.
How does P2 access the tables? Does it use NOLOCK or READ UNCOMMITTED?
Could you have P1 running again while P2 is running?
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns97665332A148Yazorman@.127.0.0.1...
> Rick (Rick@.nowhere.com) writes:
> I'm afraid that this introduction is not enough to say anything for sure.
> Seeing the code would have helped?
> Of course, the missing FK constraint is not good, but as long as you know
> that the data you insert is consistent, it is not a problem. And, anyway,
> if you were to INSERT data into T2 where the key to T1 is missing, it
> should keep on failing.
> How does P2 access the tables? Does it use NOLOCK or READ UNCOMMITTED?
> Could you have P1 running again while P2 is running?
I'm using ado.net, so the code would probably be irrelevant, even if I could
extract it from the many layers.
I was not declaring an explicit locking strategy, but instead depending on
the default (read committed?). I can only assume that when P2 read T1, it
got none or only some of the new data. I'm not sure how this could happen.
The strange thing is that when I changed the isolation level of the P1
transaction to serializable, the problem did not recur. This is troubling.
:-/|||Rick (rick@.nospam.com) writes:
> I'm using ado.net, so the code would probably be irrelevant, even if I
> could extract it from the many layers.
It may be that your code is too complex to be easily understood in a
newsgroup post, but you are wrong to assume that it is irrelevant. Without
code, I can at best guess what you are doing.
Since it helped to set the transaction isolation level to serializable for
the update process, there is obviously something you did not tell us.
My guess is that once instance of P1 runs, alerts P2. P2 starts reading T1.
At the same time a second instance of P2 starts running and deletes the
row in T2.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns9767CF95BB51EYazorman@.127.0.0.1...
> Rick (rick@.nospam.com) writes:
> It may be that your code is too complex to be easily understood in a
> newsgroup post, but you are wrong to assume that it is irrelevant. Without
> code, I can at best guess what you are doing.
> Since it helped to set the transaction isolation level to serializable for
> the update process, there is obviously something you did not tell us.
> My guess is that once instance of P1 runs, alerts P2. P2 starts reading
> T1.
> At the same time a second instance of P2 starts running and deletes the
> row in T2.
Thanks Eric. It's important to know that this should not be happening IF the
sequence of events are as I described. I can only then assume, like you,
that they are not. This gives me something to work with.|||"Rick" <Rick@.nowhere.com> wrote in message
news:uHsgDcLMGHA.1124@.TK2MSFTNGP15.phx.gbl...
> "Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
> news:Xns9767CF95BB51EYazorman@.127.0.0.1...
> Thanks Eric. It's important to know that this should not be happening IF
> the sequence of events are as I described. I can only then assume, like
> you, that they are not. This gives me something to work with.
Sorry... ERLAND!!|||Why don't you have a ON DELETE CASCADE constraint? Never depend on app
code to maintain your data integrity. This is one of many reason that
a row in a RDBMS is nothing like a record.
The way you chain code together implies a procedural design and
mindset.