Showing posts with label website. Show all posts
Showing posts with label website. Show all posts

Tuesday, March 27, 2012

Estimate Log Space for Alter Table Statement

My client's website database is hosted by a third party. I need to alter one of the column definitions for the largest table in the database. Unfortunately, the transaction log fills up if I try to alter the table. I've done all the usual stuff like truncating the log, etc., but the simple fact is that the operation requires more log space than we have available. Therefore, we need to purchase additional disk space for the database.

What I'm looking for is a way to roughly estimate how much log space will be required to alter this table so that we purchase enough but not too much additional space. The table has an identity primary key and 4 other single column indexes: one int, one datetime and two varchar(30) columns.

Any suggestions? Thanks in advance.

You can change the truncate log setting in a database if you don't need it to recover in time of emergency it is a very complicated subject so run a search for truncate log on checkpoint option for your database setting in the BOL(books online). The links below are basic guidelines from Microsoft. Hope this helps.

http://support.microsoft.com/kb/873235

http://msdn2.microsoft.com/en-us/library/aa933068(SQL.80).aspx

|||

If I remember correctly when you alter column in table, SQL server renames old one, created new table with new structure and next moves data into new table. So in your case you need at least amount of space your data table takes for log because all process has to be done at one shot.
But maybe you can do it yourself: create table with new structure and move data from old table to new table with quantity like 100 or 1000 records in one shot? Log file will be small and you should succeed. You only have to take care about identity insert if you have one in your table.

Thanks

|||

Thanks jpazgier, that's a great suggestion! I usually do the alter using Enterprise Manager directly for this client but I have scripted this type of change for other clients. I never thought about taking the generated script and breaking up the insert part of it into multiple inserts and performing the truncate log after each insert. That would reduce the log space required.

If I don't delete the old records as I go, I still need twice the data just for the old and new copies but I wouldn't need so much log space. If I trust my alterations, then I could delete the old records as they get moved into the new copy and really reduce the free space required. Not as safe but probably sufficient.

Thanks

|||

(1) You could keep the DB in simple mode while you do the data transfer.

(2) You can also have a job running to truncate the log during the transfer and let the job run every 1 minute, so you dont have to do it yourself manually.

(3) You can use bcp/Bulk Insert to transfer the data.

Sunday, March 11, 2012

Errors in SQL Server. How prevent them?

Im designing a dynamic website with Dreamweaver MX, ASP VBScript language, SQL 2000 Server and PWS as a server. The site is not available in Internet yet.

For the moment I have created all the main functions of the website. Almost all the actions that the site leads to term it does it with stored procedures (sp) on SQL Server. Those SP works well from the web application, and all the actions (to insert data, to modify data, to check data, etc.) works perfect. But I have been advised that I learn to capture the possible errors that SQL Server can return to user, and to avoid that the site fell. Someone could explain me what kind of errors can return me? And how can I solve it?

I can not understand why I need to know how to capture those errors because, if were managing to happen, the browser show us a message of error and the user try again the operation, as I have seen at many sites. After that, I should quarrel to discover why these errors happen, and then I try to solve it, or take the aid of an expert administrator. Or, can I really to prevent these potential errors and to minimize their effects?

In the other hand, I cant understand why my stored procedures are able to return errors or to bring problems to my web application, now it works well.

Thank you.

Here is an example of one of my stored procedures:

CREATE PROCEDURE check_mail_password_inscription
@.E-mail varchar(50), @.Password char(10),
@.Offer_num int, @.Date datetime, @.Motives_interest varchar(250)
As
Declare @.Buyer_num int

If Exists(select E-mail from Buyers where E-mail = @.E-mail
and Password = @.Password)
begin

select @.Buyer_num = Buyer_num
from Buyers
where E-mail = @.E-mail
and Password = @.Password

select @.Buyer_num AS Buyer_num, 1 AS Value
INSERT INTO Inscriptions_in_offers (Offer_num, Buyer_num, Date, Motives_interest)
VALUES (@.Offer_num, @.Buyer_num, @.Date, @.Motives_interest)
end
else
begin
select 0 AS Value
endAny data update can cause a deadlock and there is very little you can do to prevent it - you can minimise it but not prevent. Systems that are not designed with this in mind usually have a lot of problems when they get a few concurrent users.

Your system should always take account of the possibility of any operation failing.

In your SP what happens if the insert fails? to you still want to return a resultset?
And why return a single row resultset rather than output parameters which are much faster.
You are also returning a different shape resultset for the two paths which is a bit odd.

I would guess that you also need to read up on transaction control.|||What you recommend me to minimize the errors in my stored procedures? Now they are totally helpless. I need to use BEGIN TRANSACTION, COMMIT TRANSACTION, ROLLBACK TRANSACTION, @.@.ERROR variable, RAISERROR, RETURN statement to force an unconditional exit or sp_addmessage stored procedure? Or all together where this is possible?

If my sp fails and the action cannot be done, I need communicate it to my web application so that the user tries again the operation.

I only know this tools in general, never I used to. Would you mind give me a complete example with my stored procedure please?

CREATE PROCEDURE check_mail_password_inscription
@.E-mail varchar(50), @.Password char(10),
@.Offer_num int, @.Date datetime, @.Motives_interest varchar(250)
As
Declare @.Buyer_num int

If Exists(select E-mail from Buyers where E-mail = @.E-mail
and Password = @.Password)
begin

select @.Buyer_num = Buyer_num
from Buyers
where E-mail = @.E-mail
and Password = @.Password

select @.Buyer_num AS Buyer_num, 1 AS Value
INSERT INTO Inscriptions_in_offers (Offer_num, Buyer_num, Date, Motives_interest)
VALUES (@.Offer_num, @.Buyer_num, @.Date, @.Motives_interest)
end
else
begin
select 0 AS Value
end

I have a manual of SQL Server that says that exist two types of transactions: explicit and implicit. Explicit transaction means that begin with the BEGIN TRANSACTION statement and end with the COMMIT TRANSACTION statement. Implicit transaction means that, more or less, if you don t use the BEGIN TRANSACTION and COMMIT TRANSACTION statements, nor do you turn on implicit transactions, SQL Server autocommits the transaction. With this, I understand that is not necessary to write the statements begin tr and commit tr in my sp. It is like that?


Thank you,
Cesar

Sunday, February 26, 2012

error:40 connecting with sql server 2000

Hi
I am getting this really annoying error that I cant resolve.
I have created a website that accesses a SQL SERVER 2000 database and
it works perfectly on my home machine. The error has occurred when I
have transferred it to my hosts server.
This is the error:
An error has occurred while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the
fact that under the default settings SQL Server does not allow remote
connections. (provider: Named Pipes Provider, error: 40 - Could not
open a connection to SQL Server)
This is my connection string:
<add key="ConnectionString" value="Provider=sqloledb;Data
Source=hostsserver****,1433;Initial
Catalog=db******;User Id=dbo*******;Password=********; "/>
It says I am trying to connect to a SQL SERVER 2000 database as this is
what I devloped the site on so I do not know why it thinks I am trying
to connect to SQL SERVER 2005.
Can anyone help?Is your host database server and your home database server the same? It look
s
like that your host database server is in SQL Server 2005.
By the way do you use outside host provider? If yes, you might want to
consider giving them an e-mail. Looking at the connection string, I don't se
e
any problem:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog=
Your_Database_Name;UserId=Your_Username;
Password=Your_Password;" .
So I am thinking that the host database server might be on different port
number than 1433 or use a named instance?
Lucas
"chrisbarber1@.gmail.com" wrote:

> Hi
> I am getting this really annoying error that I cant resolve.
> I have created a website that accesses a SQL SERVER 2000 database and
> it works perfectly on my home machine. The error has occurred when I
> have transferred it to my hosts server.
> This is the error:
> An error has occurred while establishing a connection to the server.
> When connecting to SQL Server 2005, this failure may be caused by the
> fact that under the default settings SQL Server does not allow remote
> connections. (provider: Named Pipes Provider, error: 40 - Could not
> open a connection to SQL Server)
>
> This is my connection string:
> <add key="ConnectionString" value="Provider=sqloledb;Data
> Source=hostsserver****,1433;Initial
> Catalog=db******;User Id=dbo*******;Password=********; "/>
>
> It says I am trying to connect to a SQL SERVER 2000 database as this is
> what I devloped the site on so I do not know why it thinks I am trying
> to connect to SQL SERVER 2005.
> Can anyone help?
>|||Thanks for your reply.

> Is your host database server and your home database server the same?
Yes both are on sql server 2000

> By the way do you use outside host provider? If yes, you might want to
> consider giving them an e-mail.
The host providor has been absolutely hopeless.

> So I am thinking that the host database server might be on different port
> number than 1433 or use a named instance?
I'll look in to this although on the hosts control panel definately
says 1433.
Any other ideas?|||<chrisbarber1@.gmail.com> wrote in message
news:1149755323.823279.142210@.u72g2000cwu.googlegroups.com...
> Hi
> I am getting this really annoying error that I cant resolve.
> I have created a website that accesses a SQL SERVER 2000 database and
> it works perfectly on my home machine. The error has occurred when I
> have transferred it to my hosts server.
> This is the error:
> An error has occurred while establishing a connection to the server.
> When connecting to SQL Server 2005, this failure may be caused by the
> fact that under the default settings SQL Server does not allow remote
> connections. (provider: Named Pipes Provider, error: 40 - Could not
> open a connection to SQL Server)
>
It really sounds like the ISP is full of it and somehow your site is trying
to connect to a 2005 server with remote connections turned off.

> This is my connection string:
> <add key="ConnectionString" value="Provider=sqloledb;Data
> Source=hostsserver****,1433;Initial
> Catalog=db******;User Id=dbo*******;Password=********; "/>
>
> It says I am trying to connect to a SQL SERVER 2000 database as this is
> what I devloped the site on so I do not know why it thinks I am trying
> to connect to SQL SERVER 2005.
> Can anyone help?
>|||Check the value of instance config parameter: "remote access" and see
whether it is enabled..
> sp_configure 'remote access'
Jayesh
<chrisbarber1@.gmail.com> wrote in message
news:1149755323.823279.142210@.u72g2000cwu.googlegroups.com...
> Hi
> I am getting this really annoying error that I cant resolve.
> I have created a website that accesses a SQL SERVER 2000 database and
> it works perfectly on my home machine. The error has occurred when I
> have transferred it to my hosts server.
> This is the error:
> An error has occurred while establishing a connection to the server.
> When connecting to SQL Server 2005, this failure may be caused by the
> fact that under the default settings SQL Server does not allow remote
> connections. (provider: Named Pipes Provider, error: 40 - Could not
> open a connection to SQL Server)
>
> This is my connection string:
> <add key="ConnectionString" value="Provider=sqloledb;Data
> Source=hostsserver****,1433;Initial
> Catalog=db******;User Id=dbo*******;Password=********; "/>
>
> It says I am trying to connect to a SQL SERVER 2000 database as this is
> what I devloped the site on so I do not know why it thinks I am trying
> to connect to SQL SERVER 2005.
> Can anyone help?
>

error:40 connecting with sql server 2000

Hi
I am getting this really annoying error that I cant resolve.
I have created a website that accesses a SQL SERVER 2000 database and
it works perfectly on my home machine. The error has occurred when I
have transferred it to my hosts server.
This is the error:
An error has occurred while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the
fact that under the default settings SQL Server does not allow remote
connections. (provider: Named Pipes Provider, error: 40 - Could not
open a connection to SQL Server)
This is my connection string:
<add key="ConnectionString" value="Provider=sqloledb;Data
Source=hostsserver****,1433;Initial
Catalog=db******;User Id=dbo*******;Password=********; "/>
It says I am trying to connect to a SQL SERVER 2000 database as this is
what I devloped the site on so I do not know why it thinks I am trying
to connect to SQL SERVER 2005.
Can anyone help?Is your host database server and your home database server the same? It looks
like that your host database server is in SQL Server 2005.
By the way do you use outside host provider? If yes, you might want to
consider giving them an e-mail. Looking at the connection string, I don't see
any problem:
"Provider=SQLOLEDB;Data Source=Your_Server_Name;Initial Catalog=Your_Database_Name;UserId=Your_Username;Password=Your_Password;" .
So I am thinking that the host database server might be on different port
number than 1433 or use a named instance?
Lucas
"chrisbarber1@.gmail.com" wrote:
> Hi
> I am getting this really annoying error that I cant resolve.
> I have created a website that accesses a SQL SERVER 2000 database and
> it works perfectly on my home machine. The error has occurred when I
> have transferred it to my hosts server.
> This is the error:
> An error has occurred while establishing a connection to the server.
> When connecting to SQL Server 2005, this failure may be caused by the
> fact that under the default settings SQL Server does not allow remote
> connections. (provider: Named Pipes Provider, error: 40 - Could not
> open a connection to SQL Server)
>
> This is my connection string:
> <add key="ConnectionString" value="Provider=sqloledb;Data
> Source=hostsserver****,1433;Initial
> Catalog=db******;User Id=dbo*******;Password=********; "/>
>
> It says I am trying to connect to a SQL SERVER 2000 database as this is
> what I devloped the site on so I do not know why it thinks I am trying
> to connect to SQL SERVER 2005.
> Can anyone help?
>|||Thanks for your reply.
> Is your host database server and your home database server the same?
Yes both are on sql server 2000
> By the way do you use outside host provider? If yes, you might want to
> consider giving them an e-mail.
The host providor has been absolutely hopeless.
> So I am thinking that the host database server might be on different port
> number than 1433 or use a named instance?
I'll look in to this although on the hosts control panel definately
says 1433.
Any other ideas?|||<chrisbarber1@.gmail.com> wrote in message
news:1149755323.823279.142210@.u72g2000cwu.googlegroups.com...
> Hi
> I am getting this really annoying error that I cant resolve.
> I have created a website that accesses a SQL SERVER 2000 database and
> it works perfectly on my home machine. The error has occurred when I
> have transferred it to my hosts server.
> This is the error:
> An error has occurred while establishing a connection to the server.
> When connecting to SQL Server 2005, this failure may be caused by the
> fact that under the default settings SQL Server does not allow remote
> connections. (provider: Named Pipes Provider, error: 40 - Could not
> open a connection to SQL Server)
>
It really sounds like the ISP is full of it and somehow your site is trying
to connect to a 2005 server with remote connections turned off.
> This is my connection string:
> <add key="ConnectionString" value="Provider=sqloledb;Data
> Source=hostsserver****,1433;Initial
> Catalog=db******;User Id=dbo*******;Password=********; "/>
>
> It says I am trying to connect to a SQL SERVER 2000 database as this is
> what I devloped the site on so I do not know why it thinks I am trying
> to connect to SQL SERVER 2005.
> Can anyone help?
>|||Check the value of instance config parameter: "remote access" and see
whether it is enabled..
> sp_configure 'remote access'
Jayesh
<chrisbarber1@.gmail.com> wrote in message
news:1149755323.823279.142210@.u72g2000cwu.googlegroups.com...
> Hi
> I am getting this really annoying error that I cant resolve.
> I have created a website that accesses a SQL SERVER 2000 database and
> it works perfectly on my home machine. The error has occurred when I
> have transferred it to my hosts server.
> This is the error:
> An error has occurred while establishing a connection to the server.
> When connecting to SQL Server 2005, this failure may be caused by the
> fact that under the default settings SQL Server does not allow remote
> connections. (provider: Named Pipes Provider, error: 40 - Could not
> open a connection to SQL Server)
>
> This is my connection string:
> <add key="ConnectionString" value="Provider=sqloledb;Data
> Source=hostsserver****,1433;Initial
> Catalog=db******;User Id=dbo*******;Password=********; "/>
>
> It says I am trying to connect to a SQL SERVER 2000 database as this is
> what I devloped the site on so I do not know why it thinks I am trying
> to connect to SQL SERVER 2005.
> Can anyone help?
>