Showing posts with label update. Show all posts
Showing posts with label update. Show all posts

Sunday, March 11, 2012

Cant delete records from DB .. says : Too many rows were affected by update.

Hi,

I've added multiple records with same info during practice. Now I"m trying to delete those records from SQL Server DB. but it says

"Key column information is insufficient or incorrect. To many rows were affected by update."

What to do, to delete these records?

Appreciated..if you post the code we can help you out but the error message you're getting means you're trying to update a row that has a duplicate. So, if your table had a primary key, you couldn't have a duplicate row and wouldn't have a problem.

hth|||Add a new column to your table and give each record a unique value for the column. Quickest way to do this is to add an Indentity column to the table (SQL Server will add the unique values). Delete the records you don't want and then you can remove the Indentity column if you want.

Can't delete job

When attempt to delete a job, the following error is
encountered:
Cannot add, update, or delete a job (or its steps or
schedules) that originated from an MSX server.
How would you reslove this?
Thanks,
BenDo you have master-target server configuration setup? If not, did you
recently rename your SQL Server?
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Ben" <bluebells88@.yahoo.com> wrote in message
news:379601c3fdd4$05d89540$a001280a@.phx.gbl...
When attempt to delete a job, the following error is
encountered:
Cannot add, update, or delete a job (or its steps or
schedules) that originated from an MSX server.
How would you reslove this?
Thanks,
Ben|||Sorry, what is 'master-target server configuration
setup'?
The machine joined a domain group after the job is
created.
Thanks,
Ben
>--Original Message--
>Do you have master-target server configuration setup? If
not, did you
>recently rename your SQL Server?
>--
>HTH,
>Vyas, MVP (SQL Server)
>http://vyaskn.tripod.com/
>Is .NET important for a database professional?
>http://vyaskn.tripod.com/poll.htm
>
>"Ben" <bluebells88@.yahoo.com> wrote in message
>news:379601c3fdd4$05d89540$a001280a@.phx.gbl...
>When attempt to delete a job, the following error is
>encountered:
>Cannot add, update, or delete a job (or its steps or
>schedules) that originated from an MSX server.
>How would you reslove this?
>Thanks,
>Ben
>
>.
>|||You probably have incorrect machine name in msdb..sysjobs. The old machine
name is still in msdb..sysjobs. Since you changed the machine name, SQLAgent
now thinks that this job is owned by a master server. You can change
the machine names for all jobs with below SQL Statement. Warning: Hacking
system tables is not supported and should be done with care (below should be
rather safe, though).
DECLARE @.srv sysname
SET @.srv = CAST(SERVERPROPERTY('ServerName') AS sysname)
UPDATE sysjobs SET originating_server = @.srv
NOTE:
If this is a target server (you have jobs sent from a master server), you
have to exclude them, so you don't transfer those jobs into local jobs:
WHERE originating_server = 'oldservname'
If you want to do this the supported way, see below KB article
http://support.microsoft.com/default.aspx?scid=kb;en-us;281642
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Ben" <bluebells88@.yahoo.com> wrote in message
news:44ba01c3fe7b$b69c3970$a101280a@.phx.gbl...
> Sorry, what is 'master-target server configuration
> setup'?
> The machine joined a domain group after the job is
> created.
> Thanks,
> Ben
> >--Original Message--
> >Do you have master-target server configuration setup? If
> not, did you
> >recently rename your SQL Server?
> >--
> >HTH,
> >Vyas, MVP (SQL Server)
> >http://vyaskn.tripod.com/
> >Is .NET important for a database professional?
> >http://vyaskn.tripod.com/poll.htm
> >
> >
> >"Ben" <bluebells88@.yahoo.com> wrote in message
> >news:379601c3fdd4$05d89540$a001280a@.phx.gbl...
> >When attempt to delete a job, the following error is
> >encountered:
> >
> >Cannot add, update, or delete a job (or its steps or
> >schedules) that originated from an MSX server.
> >
> >How would you reslove this?
> >
> >Thanks,
> >Ben
> >
> >
> >.
> >|||Thanks all for the helps.
Ben
>--Original Message--
>You probably have incorrect machine name in
msdb..sysjobs. The old machine
>name is still in msdb..sysjobs. Since you changed the
machine name, SQLAgent
>now thinks that this job is owned by a master server.
You can change
>the machine names for all jobs with below SQL Statement.
Warning: Hacking
>system tables is not supported and should be done with
care (below should be
>rather safe, though).
>DECLARE @.srv sysname
>SET @.srv = CAST(SERVERPROPERTY('ServerName') AS sysname)
>UPDATE sysjobs SET originating_server = @.srv
>
>NOTE:
>If this is a target server (you have jobs sent from a
master server), you
>have to exclude them, so you don't transfer those jobs
into local jobs:
>WHERE originating_server = 'oldservname'
>
>If you want to do this the supported way, see below KB
article
>http://support.microsoft.com/default.aspx?scid=kb;en-
us;281642
>
>--
>Tibor Karaszi, SQL Server MVP
>Archive at:
>http://groups.google.com/groups?
oi=djq&as_ugroup=microsoft.public.sqlserver
>
>"Ben" <bluebells88@.yahoo.com> wrote in message
>news:44ba01c3fe7b$b69c3970$a101280a@.phx.gbl...
>> Sorry, what is 'master-target server configuration
>> setup'?
>> The machine joined a domain group after the job is
>> created.
>> Thanks,
>> Ben
>> >--Original Message--
>> >Do you have master-target server configuration setup?
If
>> not, did you
>> >recently rename your SQL Server?
>> >--
>> >HTH,
>> >Vyas, MVP (SQL Server)
>> >http://vyaskn.tripod.com/
>> >Is .NET important for a database professional?
>> >http://vyaskn.tripod.com/poll.htm
>> >
>> >
>> >"Ben" <bluebells88@.yahoo.com> wrote in message
>> >news:379601c3fdd4$05d89540$a001280a@.phx.gbl...
>> >When attempt to delete a job, the following error is
>> >encountered:
>> >
>> >Cannot add, update, or delete a job (or its steps or
>> >schedules) that originated from an MSX server.
>> >
>> >How would you reslove this?
>> >
>> >Thanks,
>> >Ben
>> >
>> >
>> >.
>> >
>
>.
>

Can't delete job

When attempt to delete a job, the following error is
encountered:
Cannot add, update, or delete a job (or its steps or
schedules) that originated from an MSX server.
How would you reslove this?
Thanks,
BenDo you have master-target server configuration setup? If not, did you
recently rename your SQL Server?
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Ben" <bluebells88@.yahoo.com> wrote in message
news:379601c3fdd4$05d89540$a001280a@.phx.gbl...
When attempt to delete a job, the following error is
encountered:
Cannot add, update, or delete a job (or its steps or
schedules) that originated from an MSX server.
How would you reslove this?
Thanks,
Ben|||Sorry, what is 'master-target server configuration
setup'?
The machine joined a domain group after the job is
created.
Thanks,
Ben

>--Original Message--
>Do you have master-target server configuration setup? If
not, did you
>recently rename your SQL Server?
>--
>HTH,
>Vyas, MVP (SQL Server)
>http://vyaskn.tripod.com/
>Is .NET important for a database professional?
>http://vyaskn.tripod.com/poll.htm
>
>"Ben" <bluebells88@.yahoo.com> wrote in message
>news:379601c3fdd4$05d89540$a001280a@.phx.gbl...
>When attempt to delete a job, the following error is
>encountered:
>Cannot add, update, or delete a job (or its steps or
>schedules) that originated from an MSX server.
>How would you reslove this?
>Thanks,
>Ben
>
>.
>|||You probably have incorrect machine name in msdb..sysjobs. The old machine
name is still in msdb..sysjobs. Since you changed the machine name, SQLAgent
now thinks that this job is owned by a master server. You can change
the machine names for all jobs with below SQL Statement. Warning: Hacking
system tables is not supported and should be done with care (below should be
rather safe, though).
DECLARE @.srv sysname
SET @.srv = CAST(SERVERPROPERTY('ServerName') AS sysname)
UPDATE sysjobs SET originating_server = @.srv
NOTE:
If this is a target server (you have jobs sent from a master server), you
have to exclude them, so you don't transfer those jobs into local jobs:
WHERE originating_server = 'oldservname'
If you want to do this the supported way, see below KB article
http://support.microsoft.com/defaul...kb;en-us;281642
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=...ublic.sqlserver
"Ben" <bluebells88@.yahoo.com> wrote in message
news:44ba01c3fe7b$b69c3970$a101280a@.phx.gbl...
> Sorry, what is 'master-target server configuration
> setup'?
> The machine joined a domain group after the job is
> created.
> Thanks,
> Ben
>
> not, did you|||tibor,
I am trying your tip and obviously doing something wrong.
original server name was foxapp
new server name is foxsql
this is what I type but get originating_server not a valid column name?
DECLARE @.srv sysname
SET @.srv = CAST(SERVERPROPERTY('foxsql') AS sysname)
UPDATE sysjobs SET originating_server = @.srv
WHERE orginating_server = 'foxapp'
could you pls tell me what I did wrong thanks
mitch|||You shouldn't replace 'ServerName' inside the function call.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"mitch" <anonymous@.discussions.microsoft.com> wrote in message
news:DE663F9F-66CD-407B-97D9-0B51860DDB1E@.microsoft.com...
> tibor,
> I am trying your tip and obviously doing something wrong.
> original server name was foxapp
> new server name is foxsql
> this is what I type but get originating_server not a valid column name?
> DECLARE @.srv sysname
> SET @.srv = CAST(SERVERPROPERTY('foxsql') AS sysname)
> UPDATE sysjobs SET originating_server = @.srv
> WHERE orginating_server = 'foxapp'
> could you pls tell me what I did wrong thanks
> mitch|||Tibor,
thank you very much!
excellent fix!
mitch

Thursday, March 8, 2012

Can't create stored procedure with access 2003 when connected to SQL 2005

It tells me I may have to update a driver.

Where can I find this update and what is updated?

Thanks for the help.

More than likely you have a disconnect with the MDAC. You can download the latest version of that here:

http://msdn.microsoft.com/data/mdac/default.aspx

If that doesn't work out, you might need the SQL Server Native Client. You can find that here:

http://msdn.microsoft.com/data/sqlnative/default.aspx

Buck

Saturday, February 25, 2012

Can't construct correct UPDATE script

I messed up an insert script somewhere and need to correct my data. The tabl
e which needs fixing is:
Table Mailings
AddressID int
PersonID int
NextMailDate datetime
Sample data:
AddressID PersonID NextMailDate
123 4 03/10/2005
123 4 08/30/2005
123 4 12/30/2005
123 12 07/05/2005
Data should be:
123 4 03/10/2005
123 4 NULL
123 4 NULL
123 12 07/05/2005
I need to set NextMailDate to NULL for each PersonID but the max(PersonID) h
aving a date > than the
system date.
I am lost, as you can see from my lame attempt. Thanks, Lars
update mailings
set nextmaildate = null
where addressid = (SELECT AddressID FROM Mailings m ) and
personid <> (SELECT max(PersonID) FROM Mailings WHERE AddressID = m.addressi
d) and
nextmaildate >= convert(nvarchar, getdate(), 112)larzeb wrote:
> I messed up an insert script somewhere and need to correct my data.
> The table which needs fixing is:
> Table Mailings
> AddressID int
> PersonID int
> NextMailDate datetime
> Sample data:
> AddressID PersonID NextMailDate
> 123 4 03/10/2005
> 123 4 08/30/2005
> 123 4 12/30/2005
> 123 12 07/05/2005
> Data should be:
> 123 4 03/10/2005
> 123 4 NULL
> 123 4 NULL
> 123 12 07/05/2005
> I need to set NextMailDate to NULL for each PersonID but the
> max(PersonID) having a date > than the system date.
>
What the PK on this table? I'm not sure I understand the requirement.
Are you saying you want to set the NextMailDate to NULL if a Person has
a NextMailDate > System Date? Are you showing us dates in European
format? I see a 03/10/2005, which in the USA is March 10th (presumably
less than the system date).
Based on the sample data, it looks as though you want a NULL
NextMailDate for all dates for a person that are not equal to the
MIN(NextMailDate).
Could you clarify?
David Gugick
Imceda Software
www.imceda.com|||David,
Sorry for the incomplete explanation. Yes, the dates are mm/dd/yyyy.
I did not include the PK. It is an identity column. The AddressID is a forei
gn key into the Address
table and the PersonID is a foreign key into the Person table.
For a single AddressID, I need to identify the MAX(PersonID) so that the com
bination of AddressID
and MAX(PersondID) is not affected.
For all other combinations of any single AddressID and PersonIDs, I need to
make the NextMailDate
NULL where the existing NextMailDate is equal to or greater than the system
date.
The data illustration was for a single AddressID.
Thanks, Lars
On Mon, 23 May 2005 14:52:24 -0400, "David Gugick" <davidg-nospam@.imceda.com
> wrote:

>larzeb wrote:
>What the PK on this table? I'm not sure I understand the requirement.
>Are you saying you want to set the NextMailDate to NULL if a Person has
>a NextMailDate > System Date? Are you showing us dates in European
>format? I see a 03/10/2005, which in the USA is March 10th (presumably
>less than the system date).
>Based on the sample data, it looks as though you want a NULL
>NextMailDate for all dates for a person that are not equal to the
>MIN(NextMailDate).
>Could you clarify?|||Firstly, don't depend on Identity columns as a guarantee of entry sequence.
You
should instead add a column called DateTime column that marks when the row w
as
added.

> For a single AddressID, I need to identify
> the MAX(PersonID) so that the combination of AddressID
> and MAX(PersondID) is not affected.
This logic does not appear to match your sample results. Given your
requirements, I would expect the following results
AddressId PersonId NextMailDate
123 4 2005-03-10
123 4 Null
123 4 Null
123 12 Null
If this is not the case, then why should the last entry for a given AddressI
d
and PersonId but a date greater than the system date not get reset?
Thomas
"larzeb" <larzeb@.community.nospam> wrote in message
news:627491d56eo3jrbu313505o318e1kn3bh3@.
4ax.com...
>I messed up an insert script somewhere and need to correct my data. The tab
le
>which needs fixing is:
> Table Mailings
> AddressID int
> PersonID int
> NextMailDate datetime
> Sample data:
> AddressID PersonID NextMailDate
> 123 4 03/10/2005
> 123 4 08/30/2005
> 123 4 12/30/2005
> 123 12 07/05/2005
> Data should be:
> 123 4 03/10/2005
> 123 4 NULL
> 123 4 NULL
> 123 12 07/05/2005
> I need to set NextMailDate to NULL for each PersonID but the max(PersonID)
> having a date > than the
> system date.
> I am lost, as you can see from my lame attempt. Thanks, Lars
>
> update mailings
> set nextmaildate = null
> where addressid = (SELECT AddressID FROM Mailings m ) and
> personid <> (SELECT max(PersonID) FROM Mailings WHERE AddressID =
> m.addressid) and
> nextmaildate >= convert(nvarchar, getdate(), 112)|||On Mon, 23 May 2005 12:44:51 -0700, larzeb wrote:
>David,
>Sorry for the incomplete explanation. Yes, the dates are mm/dd/yyyy.
>I did not include the PK. It is an identity column. The AddressID is a fore
ign key into the Address
>table and the PersonID is a foreign key into the Person table.
>For a single AddressID, I need to identify the MAX(PersonID) so that the co
mbination of AddressID
>and MAX(PersondID) is not affected.
>For all other combinations of any single AddressID and PersonIDs, I need to
make the NextMailDate
>NULL where the existing NextMailDate is equal to or greater than the system date.[/
color]
(snip)
Hi larzeb,
Not sure if I understand the requirements correctly, but maybe this is
what you want:
UPDATE Mailings
SET NextMailDate IS NULL
WHERE NextMailDate > CURRENT_TIMESTAMP
AND PersonID <> (SELECT MAX(PersonID)
FROM Mailings AS m2
WHERE m2.AddressID = Mailings.AddressID)
Try on test data first. Run inside a transaction, and check the results
before executing COMMIT (or ROLLBACK if the results are wrong).
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Looking at the problem again, Hugo's response would be the solution you want
.
That said this is a pretty bizarre situation asking for the Max personId.
Thomas
"Thomas Coleman" <replyingroup@.anywhere.com> wrote in message
news:erNavS9XFHA.3620@.TK2MSFTNGP09.phx.gbl...
> Firstly, don't depend on Identity columns as a guarantee of entry sequence
.
> You should instead add a column called DateTime column that marks when the
row
> was added.
>
> This logic does not appear to match your sample results. Given your
> requirements, I would expect the following results
> AddressId PersonId NextMailDate
> 123 4 2005-03-10
> 123 4 Null
> 123 4 Null
> 123 12 Null
> If this is not the case, then why should the last entry for a given Addres
sId
> and PersonId but a date greater than the system date not get reset?
>
> Thomas
>
> "larzeb" <larzeb@.community.nospam> wrote in message
> news:627491d56eo3jrbu313505o318e1kn3bh3@.
4ax.com...
>|||On Mon, 23 May 2005 13:33:08 -0700, Thomas Coleman wrote:

>Looking at the problem again, Hugo's response would be the solution you wan
t.
>That said this is a pretty bizarre situation asking for the Max personId.
Hi Thomas,
My thoughts exactly - that's why I thought that I might have misread
something :)
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Friday, February 24, 2012

Can't connect using SqlClient after creating new database.

Hi,

I am writing a c# console application that allows you to update a database to a specified version. It does this by running a set of scripts that are listed in an xml manifest.

The application also provides an option to create the database and then run scripts to update it.

I have a method that reads blocks of SQL from each script and runs them using the ADO.NET classes in the SqlClient namespace.

I am finding that after the application runs the script to create the database, the first time the application tries to connect to that new database the connection attempt fails. The error I receive is :-

Cannot open database {dbname} requested by the login. The login failed.
Login failed for user {user}

I find that if I set the thread to sleep for 3 seconds after the database is created, I can then connect without the error occurring, but this is a bit of a nasty hack. I'd prefer to find a better solution.

This is occurring against a local SQL Server Express instance.

My machine is reasonable. 3.4 Ghz. 2Gb RAM, so I wouldn't have thought there's any problems in that regard.

Does anyone have any pointers, firstly as to why this is occurring, and secondly, how I might solve this problem in a nicer way?

Thanks,

David.

Hi David,

This is strange behaviour. Are you using Windows auth or SQL auth? Also, are there any errors written to your error log?

Thanks,
Il-Sung.

|||

Hi ll-Sung,

Sorry it has taken so long for me to get back to you about this.

My SQL Express is set up for Windows Auth only, and I am connecting as such.

The exception I receive when I try to connect after creating the database is :-

Cannot open database "DatabaseName" requested by the login. The login failed.

Login failed for user 'Domain\UserName'.

Both the SQL Log and the Windows Event Log display a series of informational messages that occur during the creation of the database. Things like :-

Setting database option ANSI_PADDING to OFF for database DatabaseName

Also in the logs, I receive a Failure Audit error message. This occurs before any of the informational messages occur. It looks like :-

Login failed for user 'Domain\UserName'. [CLIENT: <local machine>]

However this login failure message appears whether or not the database creation succeeds or not (ie the process succeeds when I have my Sleep command in).

So overall, I guess there is no error in any of the logs indicating why this is occurring.

The SQL I am using to create the database is a script that I made simply by scripting off the db in Management Studio. I did not muck around with this at all except to put placeholders in for the database name.

Any further help you can provide for this would be much appreciated.

Thanks,

David.