Showing posts with label due. Show all posts
Showing posts with label due. Show all posts

Monday, March 26, 2012

Problems due to @@IDENTITY

I have a database that sits on SQL Server 2000 and the client is Access XP
connecting to SQL via ODBC.
The database has been in use since November 2003 and all has been working
well. However......over the past w a strange thing has been happening
that, when new customer details were entered and the record was saved, the
displayed record would change to that of another although the new record had
been saved to the table.
At first I thought it was Access playing around (bless it) but have since
discovered the true cause. Whenever a new customer is entered, a SQL
trigger fires that will also create a dummy record in another table
(tbl_MainCaseEntry) ready for the user to enter details. There is an
essential reason for the trigger but it is too long winded to explain why.
The trigger reads:
CREATE TRIGGER trg_NewCustomer
ON tbl_Customer
FOR INSERT
AS
BEGIN
DECLARE @.CustID INT, @.CaseCount INT
SET @.CustID = (SELECT CustomerID FROM Inserted)
INSERT INTO tbl_MainCaseEntry (CustomerID) VALUES(@.CustID)
END
The field CustomerID in tbl_MainCaseEntry is the foreign key with the table
having it's own primary key of MainID (set as an identity field seeded
(1,1)).
I have since discovered via the Query Analyser that @.@.IDENTITY is pulling
back the last identity field for the entire statement (in this case the
MainID in tbl_MainCaseEntry for the new record created by the trigger).
Is there any way that I can stop this from happening by using
IDENT_CURRENT('tbl_Customer') and making sure that @.@.IDENTITY is forced back
to this value? I have tried to use SET @.@.IDENTITY =
IDENT_CURRENT('tbl_Customer') but this does not work.
Any advice would be appreciated as this is driving me mad!!
Regards
DazzaUse SCOPE_IDENTITY, not @.@.IDENTITY. This side effect is well documented.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Dazza" <Post2Group@.Only.com> wrote in message
news:#3683HKMFHA.1096@.tk2msftngp13.phx.gbl...
> I have a database that sits on SQL Server 2000 and the client is Access XP
> connecting to SQL via ODBC.
> The database has been in use since November 2003 and all has been working
> well. However......over the past w a strange thing has been
happening
> that, when new customer details were entered and the record was saved, the
> displayed record would change to that of another although the new record
had
> been saved to the table.
> At first I thought it was Access playing around (bless it) but have since
> discovered the true cause. Whenever a new customer is entered, a SQL
> trigger fires that will also create a dummy record in another table
> (tbl_MainCaseEntry) ready for the user to enter details. There is an
> essential reason for the trigger but it is too long winded to explain why.
> The trigger reads:
> CREATE TRIGGER trg_NewCustomer
> ON tbl_Customer
> FOR INSERT
> AS
> BEGIN
> DECLARE @.CustID INT, @.CaseCount INT
> SET @.CustID = (SELECT CustomerID FROM Inserted)
> INSERT INTO tbl_MainCaseEntry (CustomerID) VALUES(@.CustID)
> END
> The field CustomerID in tbl_MainCaseEntry is the foreign key with the
table
> having it's own primary key of MainID (set as an identity field seeded
> (1,1)).
> I have since discovered via the Query Analyser that @.@.IDENTITY is pulling
> back the last identity field for the entire statement (in this case the
> MainID in tbl_MainCaseEntry for the new record created by the trigger).
> Is there any way that I can stop this from happening by using
> IDENT_CURRENT('tbl_Customer') and making sure that @.@.IDENTITY is forced
back
> to this value? I have tried to use SET @.@.IDENTITY =
> IDENT_CURRENT('tbl_Customer') but this does not work.
> Any advice would be appreciated as this is driving me mad!!
> Regards
> Dazza
>|||Have you tried using SCOPE_IDENTITY already?
Look it up in BOL to learn more.
-Jason
"Dazza" <Post2Group@.Only.com> wrote in message
news:#3683HKMFHA.1096@.tk2msftngp13.phx.gbl...
> I have a database that sits on SQL Server 2000 and the client is Access XP
> connecting to SQL via ODBC.
> The database has been in use since November 2003 and all has been working
> well. However......over the past w a strange thing has been
happening
> that, when new customer details were entered and the record was saved, the
> displayed record would change to that of another although the new record
had
> been saved to the table.
> At first I thought it was Access playing around (bless it) but have since
> discovered the true cause. Whenever a new customer is entered, a SQL
> trigger fires that will also create a dummy record in another table
> (tbl_MainCaseEntry) ready for the user to enter details. There is an
> essential reason for the trigger but it is too long winded to explain why.
> The trigger reads:
> CREATE TRIGGER trg_NewCustomer
> ON tbl_Customer
> FOR INSERT
> AS
> BEGIN
> DECLARE @.CustID INT, @.CaseCount INT
> SET @.CustID = (SELECT CustomerID FROM Inserted)
> INSERT INTO tbl_MainCaseEntry (CustomerID) VALUES(@.CustID)
> END
> The field CustomerID in tbl_MainCaseEntry is the foreign key with the
table
> having it's own primary key of MainID (set as an identity field seeded
> (1,1)).
> I have since discovered via the Query Analyser that @.@.IDENTITY is pulling
> back the last identity field for the entire statement (in this case the
> MainID in tbl_MainCaseEntry for the new record created by the trigger).
> Is there any way that I can stop this from happening by using
> IDENT_CURRENT('tbl_Customer') and making sure that @.@.IDENTITY is forced
back
> to this value? I have tried to use SET @.@.IDENTITY =
> IDENT_CURRENT('tbl_Customer') but this does not work.
> Any advice would be appreciated as this is driving me mad!!
> Regards
> Dazza
>|||look up scope_identity in BOL
"Dazza" <Post2Group@.Only.com> wrote in message
news:%233683HKMFHA.1096@.tk2msftngp13.phx.gbl...
>I have a database that sits on SQL Server 2000 and the client is Access XP
>connecting to SQL via ODBC.
> The database has been in use since November 2003 and all has been working
> well. However......over the past w a strange thing has been
> happening that, when new customer details were entered and the record was
> saved, the displayed record would change to that of another although the
> new record had been saved to the table.
> At first I thought it was Access playing around (bless it) but have since
> discovered the true cause. Whenever a new customer is entered, a SQL
> trigger fires that will also create a dummy record in another table
> (tbl_MainCaseEntry) ready for the user to enter details. There is an
> essential reason for the trigger but it is too long winded to explain why.
> The trigger reads:
> CREATE TRIGGER trg_NewCustomer
> ON tbl_Customer
> FOR INSERT
> AS
> BEGIN
> DECLARE @.CustID INT, @.CaseCount INT
> SET @.CustID = (SELECT CustomerID FROM Inserted)
> INSERT INTO tbl_MainCaseEntry (CustomerID) VALUES(@.CustID)
> END
> The field CustomerID in tbl_MainCaseEntry is the foreign key with the
> table having it's own primary key of MainID (set as an identity field
> seeded (1,1)).
> I have since discovered via the Query Analyser that @.@.IDENTITY is pulling
> back the last identity field for the entire statement (in this case the
> MainID in tbl_MainCaseEntry for the new record created by the trigger).
> Is there any way that I can stop this from happening by using
> IDENT_CURRENT('tbl_Customer') and making sure that @.@.IDENTITY is forced
> back to this value? I have tried to use SET @.@.IDENTITY =
> IDENT_CURRENT('tbl_Customer') but this does not work.
> Any advice would be appreciated as this is driving me mad!!
> Regards
> Dazza
>|||I have looked in the BOL regards this feature but cannot understand it's
exact use. Where abouts in my trigger do I use SCOPE_IDENTITY() and what is
the syntax please?
All BOL seems to show is that it will display the identity of the table
where the focus starts (ie tbl_Customer) by using SELECT SCOPE_IDENTITY() AS
[SCOPE_IDENTITY].
Regards
Dazza
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uoXHLKKMFHA.1176@.TK2MSFTNGP15.phx.gbl...
> Use SCOPE_IDENTITY, not @.@.IDENTITY. This side effect is well documented.
> --
> Please post DDL, sample data and desired results.
> See http://www.aspfaq.com/5006 for info.
>
>
> "Dazza" <Post2Group@.Only.com> wrote in message
> news:#3683HKMFHA.1096@.tk2msftngp13.phx.gbl...
> happening
> had
> table
> back
>|||@.@.IDENTITY is fine to use within the trigger.
But if you want the calling code to return the identity value generated by
its INSERT statement (not the INSERT in the trigger), use SCOPE_IDENTITY()
in the calling code. http://www.aspfaq.com/2174
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Dazza" <Post2Group@.Only.com> wrote in message
news:#kky3OKMFHA.2384@.tk2msftngp13.phx.gbl...
> I have looked in the BOL regards this feature but cannot understand it's
> exact use. Where abouts in my trigger do I use SCOPE_IDENTITY() and what
is
> the syntax please?
> All BOL seems to show is that it will display the identity of the table
> where the focus starts (ie tbl_Customer) by using SELECT SCOPE_IDENTITY()
AS
> [SCOPE_IDENTITY].
> Regards
> Dazza
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uoXHLKKMFHA.1176@.TK2MSFTNGP15.phx.gbl...
documented.
working
record
since
pulling
>|||I also note another problem here.
I guess you assume that inserts always happen in singleton? You need this
code to be multi-row aware. For example, watch what happens when you do
this:
INSERT Customers(col1, ..., colN)
SELECT 'col1', ..., colN
UNION
SELECT 'col1', ..., colN
To correct this, your INSERT statement inside the trigger should simply be:
INSERT tbl_MainCaseEntry (CustomerID)
SELECT CustomerID FROM Inserted
Or, change the calling stored procedure to handle the logging part of this,
and eliminate the need for a trigger at all. You do control access to this
table via stored procedures, right?
In any case, the calling app can't expect to get back a single @.@.IDENTITY or
SCOPE_IDENTITY() in the multi-row insert case.
(I also think you should consider dropping the superfluous tbl_ prefix, but
that's just an opinion.)
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.|||Aaron
Many thanks for the advice.
I do not use SPs for the entry or retrieval of the data in forms as the
front-end uses linked tables. I have been working with SQL Server for about
a year (mostly admin) and still have a lot to learn regards development
methods for front-end access clients. The database in question is my first
real production development project but there are more to come I have been
told !!
Regards
Dazza
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:%23PMTcUKMFHA.2420@.TK2MSFTNGP12.phx.gbl...
>I also note another problem here.
>
> I guess you assume that inserts always happen in singleton? You need this
> code to be multi-row aware. For example, watch what happens when you do
> this:
> INSERT Customers(col1, ..., colN)
> SELECT 'col1', ..., colN
> UNION
> SELECT 'col1', ..., colN
> To correct this, your INSERT statement inside the trigger should simply
> be:
> INSERT tbl_MainCaseEntry (CustomerID)
> SELECT CustomerID FROM Inserted
> Or, change the calling stored procedure to handle the logging part of
> this,
> and eliminate the need for a trigger at all. You do control access to
> this
> table via stored procedures, right?
> In any case, the calling app can't expect to get back a single @.@.IDENTITY
> or
> SCOPE_IDENTITY() in the multi-row insert case.
> (I also think you should consider dropping the superfluous tbl_ prefix,
> but
> that's just an opinion.)
> --
> Please post DDL, sample data and desired results.
> See http://www.aspfaq.com/5006 for info.
>

Wednesday, March 21, 2012

Problems Connecting to Server Due to Deliting of Default DB

Hlp!
I have made a stoopid mistake of deleting the DB that was sat to default with Enterprise Manager. Now I can't use Enterprise Manager to work with any of my DB's.

Don't get me wrong, the server is still running, and I am able to view all the old folders in IIS, I can log into and add content to different sites I am working with.
But Ican not add new DB's, make backups or modify excisting tables and so on.

There must be a way to make another Db my new defalut? Pls say it is, so I don't need to reinstall, cause then I will loose data the way it is now.

Pls tell me there is a someway easy way around this issue.

slopee
Sad n' bitterEXEC sp_defaultdb 'User', 'DB'|||I will try this in commandline, and put my username, and the DB i want for default

If this does not work I hope someone can give mestep by step guiding, that way I know what I am doing:)) I am not even sure this is to be run from cmd, or where i should run it:))

Will try this, and let you know how it went.

slopee|||Ok, sure what you wrote is totally correct, but I am afraid I am going to need more then that. I will need a step by step guide on howto do this, cause i didn't work from cmd line.

If someone knows what to do here, pls guide me.

slopee|||Clearly I need help. I can barely spell, ("Deliting" lol) how should I possible manage to apply the line you submitted?;-)

Come on y'all, surely there is someone how can give me basic details? I need it explained in details, and step-by-step pls.

s|||From MS Support (http://support.microsoft.com/default.aspx?scid=kb;en-us;307864&Product=sql):

f the user's default database no longer exists, or has been marked suspect, use the ISQL command line utility to change the user's default database to a database that is currently available for a connection.

1. At a command line prompt, type the following and then press ENTER: C:\>isql -E

2. At the isql prompt, type the following and then press ENTER: 1>sp_defaultdb 'user's_login', 'master'

3. At the second prompt, type the following and then press ENTER:2>go|||Great.

Thx y'all.

s

Monday, March 12, 2012

problems

Microsoft OLE DB Provider for ODBC Drivers
error '80004005'
Specified driver could not be loaded due to system error
126 (SQL Server).Problem with the MDAC installation of the Driver or dependent component.
Stop all applications that use SQL Server and ODBC. Try re-installing the
latest MDAC stack for your client.
Install the MDAC security patch:
http://www.microsoft.com/technet/tr...chnet/security/
Bulletin/MS04-003.asp
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.|||In the article on this link you will find a lot of info how to troubleshoot
this error: http://support.microsoft.com/defaul...b;EN-US;306518.
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"pedro" <anonymous@.discussions.microsoft.com> wrote in message
news:041e01c3dede$90fd4810$a301280a@.phx.gbl...
quote:

> Microsoft OLE DB Provider for ODBC Drivers
> error '80004005'
> Specified driver could not be loaded due to system error
> 126 (SQL Server).
>

problemas con el SQL 7.0

Microsoft OLE DB Provider for ODBC Drivers
error '80004005'
Specified driver could not be loaded due to system error
126 (SQL Server).
alguien puede darme alguna posible solucionTry running Dependency Walker with any ODBC application. There is a
profiling option that will help you identify the problem component.
www.dependencywalker.com
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.

Problem: What's that sql script doing ?

Hello !
Due to a lack of SQL server i am wondering, what that sql script is
doing. It it is part of a VB macro.
UPDATE address AS A SET ZIP=(SELECT FIRST(ZIP) FROM address WHERE
ZIP<>A.ZIP)
tnx in advance, Guido StepkenGuido Stepken (stepken@.little-idiot.de) writes:
quote:

> Due to a lack of SQL server i am wondering, what that sql script is
> doing. It it is part of a VB macro.
> UPDATE address AS A SET ZIP=(SELECT FIRST(ZIP) FROM address WHERE
> ZIP<>A.ZIP)

I guess it depends on which engine you run it on. On SQL Server this
happens:
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'AS'.
Server: Msg 195, Level 15, State 1, Line 1
'FIRST' is not a recognized function name.
I would guess that it intended for Access.
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||There is no such concept as "FIRST" in SQL Server. Did you mean MIN() or
MAX()? Or something else altogether?
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Guido Stepken" <stepken@.little-idiot.de> wrote in message
news:bts9rc$umu$06$1@.news.t-online.com...
quote:

> Hello !
> Due to a lack of SQL server i am wondering, what that sql script is
> doing. It it is part of a VB macro.
> UPDATE address AS A SET ZIP=(SELECT FIRST(ZIP) FROM address WHERE
> ZIP<>A.ZIP)
> tnx in advance, Guido Stepken
>
|||FIRST is an Access thing. The closest thing in T-SQL is
UPDATE address SET
ZIP = (
SELECT TOP 1 ZIP
FROM address
WHERE ZIP <> A.ZIP
)
But TOP 1 without ORDER BY is not often a good idea, and this is a
rather bizarre update query: change every ZIP in the address table to
some random other ZIP?
SK
Guido Stepken wrote:
quote:

> Hello !
> Due to a lack of SQL server i am wondering, what that sql script is
> doing. It it is part of a VB macro.
> UPDATE address AS A SET ZIP=(SELECT FIRST(ZIP) FROM address WHERE
> ZIP<>A.ZIP)
> tnx in advance, Guido Stepken
>
|||Steve Kass wrote:
quote:

> FIRST is an Access thing. The closest thing in T-SQL is

Interesting...
quote:

> UPDATE address SET
> ZIP = (
> SELECT TOP 1 ZIP
> FROM address
> WHERE ZIP <> A.ZIP
> )
>

You rather mean:
UPDATE address AS A SET
ZIP = (
SELECT TOP 1 ZIP
FROM address
WHERE ZIP <> A.ZIP)
does it work on T-SQL ?
quote:

> But TOP 1 without ORDER BY is not often a good idea, and this is a
> rather bizarre update query: change every ZIP in the address table to
> some random other ZIP?

Bizarre ... a SQL attack on data warehouse, ERP, CRM, - programs,
address books, outlook ... ?
quote:

> SK
> Guido Stepken wrote:
>
>
|||Guido Stepken wrote:
quote:

> Steve Kass wrote:
>
>
> Interesting...
>
> You rather mean:
> UPDATE address AS A SET
> ZIP = (
> SELECT TOP 1 ZIP
> FROM address
> WHERE ZIP <> A.ZIP)
> does it work on T-SQL ?

Guido,
T-SQL does not support an alias on the target table of an UPDATE
query, and I should have written
UPDATE address SET
ZIP = (
SELECT TOP 1 ZIP
FROM address A
WHERE A.ZIP <> ZIP
)
SK
quote:

>
>
> Bizarre ... a SQL attack on data warehouse, ERP, CRM, - programs,
> address books, outlook ... ?
>
>

Problem: What's that sql script doing ?

Hello !
Due to a lack of SQL server i am wondering, what that sql script is
doing. It it is part of a VB macro.
UPDATE address AS A SET ZIP=(SELECT FIRST(ZIP) FROM address WHERE
ZIP<>A.ZIP)
tnx in advance, Guido StepkenGuido Stepken (stepken@.little-idiot.de) writes:
> Due to a lack of SQL server i am wondering, what that sql script is
> doing. It it is part of a VB macro.
> UPDATE address AS A SET ZIP=(SELECT FIRST(ZIP) FROM address WHERE
> ZIP<>A.ZIP)
I guess it depends on which engine you run it on. On SQL Server this
happens:
Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'AS'.
Server: Msg 195, Level 15, State 1, Line 1
'FIRST' is not a recognized function name.
I would guess that it intended for Access.
--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp|||There is no such concept as "FIRST" in SQL Server. Did you mean MIN() or
MAX()? Or something else altogether?
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Guido Stepken" <stepken@.little-idiot.de> wrote in message
news:bts9rc$umu$06$1@.news.t-online.com...
> Hello !
> Due to a lack of SQL server i am wondering, what that sql script is
> doing. It it is part of a VB macro.
> UPDATE address AS A SET ZIP=(SELECT FIRST(ZIP) FROM address WHERE
> ZIP<>A.ZIP)
> tnx in advance, Guido Stepken
>|||FIRST is an Access thing. The closest thing in T-SQL is
UPDATE address SET
ZIP = (
SELECT TOP 1 ZIP
FROM address
WHERE ZIP <> A.ZIP
)
But TOP 1 without ORDER BY is not often a good idea, and this is a
rather bizarre update query: change every ZIP in the address table to
some random other ZIP?
SK
Guido Stepken wrote:
> Hello !
> Due to a lack of SQL server i am wondering, what that sql script is
> doing. It it is part of a VB macro.
> UPDATE address AS A SET ZIP=(SELECT FIRST(ZIP) FROM address WHERE
> ZIP<>A.ZIP)
> tnx in advance, Guido Stepken
>|||Steve Kass wrote:
> FIRST is an Access thing. The closest thing in T-SQL is
Interesting...
> UPDATE address SET
> ZIP = (
> SELECT TOP 1 ZIP
> FROM address
> WHERE ZIP <> A.ZIP
> )
>
You rather mean:
UPDATE address AS A SET
ZIP = (
SELECT TOP 1 ZIP
FROM address
WHERE ZIP <> A.ZIP)
does it work on T-SQL ?
> But TOP 1 without ORDER BY is not often a good idea, and this is a
> rather bizarre update query: change every ZIP in the address table to
> some random other ZIP?
Bizarre ... a SQL attack on data warehouse, ERP, CRM, - programs,
address books, outlook ... ?
> SK
> Guido Stepken wrote:
>> Hello !
>> Due to a lack of SQL server i am wondering, what that sql script is
>> doing. It it is part of a VB macro.
>> UPDATE address AS A SET ZIP=(SELECT FIRST(ZIP) FROM address WHERE
>> ZIP<>A.ZIP)
>> tnx in advance, Guido Stepken
>|||Guido Stepken wrote:
> Steve Kass wrote:
>> FIRST is an Access thing. The closest thing in T-SQL is
>
> Interesting...
>> UPDATE address SET
>> ZIP = (
>> SELECT TOP 1 ZIP
>> FROM address
>> WHERE ZIP <> A.ZIP
>> )
> You rather mean:
> UPDATE address AS A SET
> ZIP = (
> SELECT TOP 1 ZIP
> FROM address
> WHERE ZIP <> A.ZIP)
> does it work on T-SQL ?
Guido,
T-SQL does not support an alias on the target table of an UPDATE
query, and I should have written
UPDATE address SET
ZIP = (
SELECT TOP 1 ZIP
FROM address A
WHERE A.ZIP <> ZIP
)
SK
>> But TOP 1 without ORDER BY is not often a good idea, and this is a
>> rather bizarre update query: change every ZIP in the address table to
>> some random other ZIP?
>
> Bizarre ... a SQL attack on data warehouse, ERP, CRM, - programs,
> address books, outlook ... ?
>> SK
>> Guido Stepken wrote:
>> Hello !
>> Due to a lack of SQL server i am wondering, what that sql script is
>> doing. It it is part of a VB macro.
>> UPDATE address AS A SET ZIP=(SELECT FIRST(ZIP) FROM address WHERE
>> ZIP<>A.ZIP)
>> tnx in advance, Guido Stepken
>>
>