Showing posts with label webpage. Show all posts
Showing posts with label webpage. Show all posts

Tuesday, March 27, 2012

Do I need to shrink my database?

Hello,

I have SQL Server Server Man Studio Express 2005, currently having a problem with an auto populated field.

Basically I have a webpage that when I create a new item it populates a new ID, which is the primary key and read only when I go into the database backend so i cannot manually change this.

When I have been doing some testing adding fields to the table and deleting this has obviously given me new ID's such as 113, 114 etc. But on my live site I need these ID's to be sequential, so on my live site the last ID is 108, but now when I add another item the ID is 115 because the number between this and 108 have been taken up.

So my question is really do I need to shrink my database or files to take this down to 109, if so is database shrink or file the best to do? Also i have had someone add a new live item and this has been assigned 113, would I need to delete this, shrink and then re-enter?

Any suggestions would be greatley appreciated.

Many thanks.

shrinking a database does not effect IDENTITY values, you need to look at the following

DBCC CHECKIDENT (Transact-SQL)

http://msdn2.microsoft.com/en-us/library/ms176057.aspx

you could also look at running a SET IDENTITY INSERT ON;

and then updating the ID values manually to your desired values.

Derek

|||

Thank you very much for you reply. Guess I need to run a query on something like the follwoing from the link you sent:

USE Assets;
GO
DBCC CHECKIDENT ('Assets.ID', RESEED, 30);
GO

But how do you specific which row to replace?

Also how does the SET IDENTITY INSERT ON command work, sorry quite new to SQL.

|||

the easiest way for you to do this (assuming you have some form of consistency to your IDs) would be to run the following code:

SET IDENTITY_INSERT dbo.Table ON

GO

UPDATE dbo.Table SET ID = ID -30 --this is the consistency I am referring to, if your IDs are all over the place it going to not be fun lol

GO

SET IDENTITY_INSERT dbo.Table OFF

|||

You cannot use IDENTITY column if you want to ensure no gaps in the values. For example, if a particular transaction rolls back an insert then the generated identity value will be consumed and a subsequent insert will get the next higher value. If you want guaranteed sequential numbers generation then you need to do it using a sequence table yourself.

Please take a look at the link below for an implementation that shows how to use sequence table.

http://blogs.msdn.com/sqlcat/archive/2006/04/10/572848.aspx

|||Thank you for your help I have now sorted the problem. Much appreciated.

Wednesday, March 21, 2012

DNS Error

Approximately 10 minutes after I start SQL Server, some protocols such as HTTP and IRC are no longer available. When I try to open a webpage in IEX, I get a DNS error, however I can still ping the sites.
Any advice?Could you be experiencing MyDoom (http://support.microsoft.com/?kbid=836528) or Blaster (http://www.microsoft.com/security/incident/blast.mspx)? They could produce these kind of symptoms.

-PatP|||Pat,

no I don't think so, since:

-I don't have any other problems with my PC
-This started only with SQL server
-I have the latest security updates, and the extra Blaster fix
-I have a virus scanner that updates daily

Could it have something to do with the hosts file?|||Could it have something to do with the hosts file?While pretty much anything is possible, that seems unlikely to me. If that were the case, how would starting SQL Server enter into the picture (so that the sites worked before SQL starts, and fail while SQL is running)?

-PatP|||Hmm I thought because I get DNS erros...
I did the Blaster and Doom update again but no infection was found.
Anyone else any ideas what could be wrong? Or how to detect?

Edit: I checked my Event log and there is always 4 errors and 1 warning when this occurs:

Event Type: Error
Event Source: MSSQLSERVER

19012 :
SuperSocket Info: Bind failed on TCP port 1433.

Event Type: Warning
Event Source: MSSQLServer

SuperSocket-Information: (SpnRegister) : Error 1355.

But SQL Server is still working after this. I checked KB but didn't find anything.|||Just curious, but does netstat -a -n show anything relevant?

-PatP|||I`m not sure... I did some checks with that but couldn`t make to much sense
of it. Could you tell me what I`m looking for?

The problem persists... Now I am on a small network and after the said problem the whole network breaks down and I lose internet connection. I have to reboot all machines and sometimes repair the network connection Very strange indeed. I can confirm that this only happens when SQL server is started.

Other programs running:

Kaspersky AV
Webroot SypSweeper
Sometimes ICQ or mIRC
The usual XP services|||Are you absolutely certain that the machine isn't infected by Slammer (http://www.microsoft.com/technet/security/alerts/slammer.mspx)?

-PatP|||Pat I think that was it. I didn't know that my Antivirus Program may not have been aware of this exploit.

Thanks!|||De nada! Glad that you were finally able to isolate (and fix) the problem!

-PatPsql