Friday, March 30, 2012
Numerous event 17137 in event log
I am using SQL SERVER 2005 EXPRESS SP1 with an ASP.NET application, and I
get an event 17137 "Starting database MyDB" at each connection to my
database, which is a very frequent event.
The problem is that the application event log of the machine is full of this
event, with the consequence on old servers like Windows 2000 to get a message
saying the log is full and you have to empty it.
I would like to know how I can turn off the logging of SQL SERVER event 17137.
--
Olivier GIL
LAFON SAOliver GIL,
Is your MyDB in AUTO_CLOSE = ON mode? If so, you can turn this OFF, thus
keeping MyDB open by:
ALTER DATABASE MyDB SET AUTO_CLOSE OFF
That should get rid of the messages and make your accesses to MyDB run more
quickly.
RLF
"Olivier GIL" <ogil@.newsgroup.nospam> wrote in message
news:D985059D-D4CD-490B-8299-FB4924A4FF7F@.microsoft.com...
> Hello,
> I am using SQL SERVER 2005 EXPRESS SP1 with an ASP.NET application, and I
> get an event 17137 "Starting database MyDB" at each connection to my
> database, which is a very frequent event.
> The problem is that the application event log of the machine is full of
> this
> event, with the consequence on old servers like Windows 2000 to get a
> message
> saying the log is full and you have to empty it.
> I would like to know how I can turn off the logging of SQL SERVER event
> 17137.
> --
> Olivier GIL
> LAFON SA|||Hello,
AUTO_CLOSE OFF actually solves the problem.
It is surprising this option not being the default value for a CREATE
DATABASE command, knowing that the performance is better in that case.
--
Olivier GIL
LAFON SA
"Russell Fields" wrote:
> Oliver GIL,
> Is your MyDB in AUTO_CLOSE = ON mode? If so, you can turn this OFF, thus
> keeping MyDB open by:
> ALTER DATABASE MyDB SET AUTO_CLOSE OFF
> That should get rid of the messages and make your accesses to MyDB run more
> quickly.
> RLF
> "Olivier GIL" <ogil@.newsgroup.nospam> wrote in message
> news:D985059D-D4CD-490B-8299-FB4924A4FF7F@.microsoft.com...
> > Hello,
> >
> > I am using SQL SERVER 2005 EXPRESS SP1 with an ASP.NET application, and I
> > get an event 17137 "Starting database MyDB" at each connection to my
> > database, which is a very frequent event.
> >
> > The problem is that the application event log of the machine is full of
> > this
> > event, with the consequence on old servers like Windows 2000 to get a
> > message
> > saying the log is full and you have to empty it.
> >
> > I would like to know how I can turn off the logging of SQL SERVER event
> > 17137.
> >
> > --
> > Olivier GIL
> > LAFON SA
>
>|||Hi Olivier,
Regarding your concerns, you can find the following description regarding
AUTO_CLOSE OFF in SQL Server Books Online:
AUTO_CLOSE Default Value:
ON for all databases when using Microsoft SQL Server 2000 Desktop Engine or
SQL Server 2005 Express Edition, and OFF for all other editions, regardless
of operating system.
(REF: http://msdn2.microsoft.com/en-us/library/ms190249.aspx)
"The AUTO_CLOSE option is useful for desktop databases because it allows
database files to be managed as normal files. They can be moved, copied to
make backups, or even e-mailed to other users. The AUTO_CLOSE option should
not be used for databases accessed by an application that repeatedly makes
and breaks connections to SQL Server. The overhead of closing and reopening
the database between each connection will impair performance."
(REF: http://technet.microsoft.com/en-us/library/aa933082(SQL.80).aspx)
Please feel free to let us know if you have any other questions or
concerns. Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
=====================================================When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
======================================================This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================|||Hello Olivier,
AUTO_CLOSE option if ON by default only for MSDE and Express Editions.
I suggest you to take a look at the following link for further info:
http://msdn2.microsoft.com/en-us/library/ms190249.aspx
--
Ekrem Ã?nsoy
"Olivier GIL" <ogil@.newsgroup.nospam> wrote in message
news:C20E229A-83E5-4D09-9B1F-F830E84EA438@.microsoft.com...
> Hello,
> AUTO_CLOSE OFF actually solves the problem.
>
> It is surprising this option not being the default value for a CREATE
> DATABASE command, knowing that the performance is better in that case.
> --
> Olivier GIL
> LAFON SA
>
> "Russell Fields" wrote:
>> Oliver GIL,
>> Is your MyDB in AUTO_CLOSE = ON mode? If so, you can turn this OFF,
>> thus
>> keeping MyDB open by:
>> ALTER DATABASE MyDB SET AUTO_CLOSE OFF
>> That should get rid of the messages and make your accesses to MyDB run
>> more
>> quickly.
>> RLF
>> "Olivier GIL" <ogil@.newsgroup.nospam> wrote in message
>> news:D985059D-D4CD-490B-8299-FB4924A4FF7F@.microsoft.com...
>> > Hello,
>> >
>> > I am using SQL SERVER 2005 EXPRESS SP1 with an ASP.NET application, and
>> > I
>> > get an event 17137 "Starting database MyDB" at each connection to my
>> > database, which is a very frequent event.
>> >
>> > The problem is that the application event log of the machine is full of
>> > this
>> > event, with the consequence on old servers like Windows 2000 to get a
>> > message
>> > saying the log is full and you have to empty it.
>> >
>> > I would like to know how I can turn off the logging of SQL SERVER event
>> > 17137.
>> >
>> > --
>> > Olivier GIL
>> > LAFON SA
>>
Numerous event 17137 in event log
I am using SQL SERVER 2005 EXPRESS SP1 with an ASP.NET application, and I
get an event 17137 "Starting database MyDB" at each connection to my
database, which is a very frequent event.
The problem is that the application event log of the machine is full of this
event, with the consequence on old servers like Windows 2000 to get a messag
e
saying the log is full and you have to empty it.
I would like to know how I can turn off the logging of SQL SERVER event 1713
7.
Olivier GIL
LAFON SAOliver GIL,
Is your MyDB in AUTO_CLOSE = ON mode? If so, you can turn this OFF, thus
keeping MyDB open by:
ALTER DATABASE MyDB SET AUTO_CLOSE OFF
That should get rid of the messages and make your accesses to MyDB run more
quickly.
RLF
"Olivier GIL" <ogil@.newsgroup.nospam> wrote in message
news:D985059D-D4CD-490B-8299-FB4924A4FF7F@.microsoft.com...
> Hello,
> I am using SQL SERVER 2005 EXPRESS SP1 with an ASP.NET application, and I
> get an event 17137 "Starting database MyDB" at each connection to my
> database, which is a very frequent event.
> The problem is that the application event log of the machine is full of
> this
> event, with the consequence on old servers like Windows 2000 to get a
> message
> saying the log is full and you have to empty it.
> I would like to know how I can turn off the logging of SQL SERVER event
> 17137.
> --
> Olivier GIL
> LAFON SA|||Hello,
AUTO_CLOSE OFF actually solves the problem.
It is surprising this option not being the default value for a CREATE
DATABASE command, knowing that the performance is better in that case.
Olivier GIL
LAFON SA
"Russell Fields" wrote:
> Oliver GIL,
> Is your MyDB in AUTO_CLOSE = ON mode? If so, you can turn this OFF, thus
> keeping MyDB open by:
> ALTER DATABASE MyDB SET AUTO_CLOSE OFF
> That should get rid of the messages and make your accesses to MyDB run mor
e
> quickly.
> RLF
> "Olivier GIL" <ogil@.newsgroup.nospam> wrote in message
> news:D985059D-D4CD-490B-8299-FB4924A4FF7F@.microsoft.com...
>
>|||Hi Olivier,
Regarding your concerns, you can find the following description regarding
AUTO_CLOSE OFF in SQL Server Books Online:
AUTO_CLOSE Default Value:
ON for all databases when using Microsoft SQL Server 2000 Desktop Engine or
SQL Server 2005 Express Edition, and OFF for all other editions, regardless
of operating system.
(REF: http://msdn2.microsoft.com/en-us/library/ms190249.aspx)
"The AUTO_CLOSE option is useful for desktop databases because it allows
database files to be managed as normal files. They can be moved, copied to
make backups, or even e-mailed to other users. The AUTO_CLOSE option should
not be used for databases accessed by an application that repeatedly makes
and breaks connections to SQL Server. The overhead of closing and reopening
the database between each connection will impair performance."
(REF: http://technet.microsoft.com/en-us/library/aa933082(SQL.80).aspx)
Please feel free to let us know if you have any other questions or
concerns. Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
========================================
=============
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
========================================
==============
This posting is provided "AS IS" with no warranties, and confers no rights.
========================================
==============|||Hello Olivier,
AUTO_CLOSE option if ON by default only for MSDE and Express Editions.
I suggest you to take a look at the following link for further info:
http://msdn2.microsoft.com/en-us/library/ms190249.aspx
Ekrem ?nsoy
"Olivier GIL" <ogil@.newsgroup.nospam> wrote in message
news:C20E229A-83E5-4D09-9B1F-F830E84EA438@.microsoft.com...[vbcol=seagreen]
> Hello,
> AUTO_CLOSE OFF actually solves the problem.
>
> It is surprising this option not being the default value for a CREATE
> DATABASE command, knowing that the performance is better in that case.
> --
> Olivier GIL
> LAFON SA
>
> "Russell Fields" wrote:
>
Numerous event 17137 in event log
I am using SQL SERVER 2005 EXPRESS SP1 with an ASP.NET application, and I
get an event 17137 "Starting database MyDB" at each connection to my
database, which is a very frequent event.
The problem is that the application event log of the machine is full of this
event, with the consequence on old servers like Windows 2000 to get a message
saying the log is full and you have to empty it.
I would like to know how I can turn off the logging of SQL SERVER event 17137.
Olivier GIL
LAFON SA
Oliver GIL,
Is your MyDB in AUTO_CLOSE = ON mode? If so, you can turn this OFF, thus
keeping MyDB open by:
ALTER DATABASE MyDB SET AUTO_CLOSE OFF
That should get rid of the messages and make your accesses to MyDB run more
quickly.
RLF
"Olivier GIL" <ogil@.newsgroup.nospam> wrote in message
news:D985059D-D4CD-490B-8299-FB4924A4FF7F@.microsoft.com...
> Hello,
> I am using SQL SERVER 2005 EXPRESS SP1 with an ASP.NET application, and I
> get an event 17137 "Starting database MyDB" at each connection to my
> database, which is a very frequent event.
> The problem is that the application event log of the machine is full of
> this
> event, with the consequence on old servers like Windows 2000 to get a
> message
> saying the log is full and you have to empty it.
> I would like to know how I can turn off the logging of SQL SERVER event
> 17137.
> --
> Olivier GIL
> LAFON SA
|||Hello,
AUTO_CLOSE OFF actually solves the problem.
It is surprising this option not being the default value for a CREATE
DATABASE command, knowing that the performance is better in that case.
Olivier GIL
LAFON SA
"Russell Fields" wrote:
> Oliver GIL,
> Is your MyDB in AUTO_CLOSE = ON mode? If so, you can turn this OFF, thus
> keeping MyDB open by:
> ALTER DATABASE MyDB SET AUTO_CLOSE OFF
> That should get rid of the messages and make your accesses to MyDB run more
> quickly.
> RLF
> "Olivier GIL" <ogil@.newsgroup.nospam> wrote in message
> news:D985059D-D4CD-490B-8299-FB4924A4FF7F@.microsoft.com...
>
>
|||Hi Olivier,
Regarding your concerns, you can find the following description regarding
AUTO_CLOSE OFF in SQL Server Books Online:
AUTO_CLOSE Default Value:
ON for all databases when using Microsoft SQL Server 2000 Desktop Engine or
SQL Server 2005 Express Edition, and OFF for all other editions, regardless
of operating system.
(REF: http://msdn2.microsoft.com/en-us/library/ms190249.aspx)
"The AUTO_CLOSE option is useful for desktop databases because it allows
database files to be managed as normal files. They can be moved, copied to
make backups, or even e-mailed to other users. The AUTO_CLOSE option should
not be used for databases accessed by an application that repeatedly makes
and breaks connections to SQL Server. The overhead of closing and reopening
the database between each connection will impair performance."
(REF: http://technet.microsoft.com/en-us/library/aa933082(SQL.80).aspx)
Please feel free to let us know if you have any other questions or
concerns. Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
================================================== ===
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
================================================== ====
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== ====
|||Hello Olivier,
AUTO_CLOSE option if ON by default only for MSDE and Express Editions.
I suggest you to take a look at the following link for further info:
http://msdn2.microsoft.com/en-us/library/ms190249.aspx
Ekrem ?nsoy
"Olivier GIL" <ogil@.newsgroup.nospam> wrote in message
news:C20E229A-83E5-4D09-9B1F-F830E84EA438@.microsoft.com...[vbcol=seagreen]
> Hello,
> AUTO_CLOSE OFF actually solves the problem.
>
> It is surprising this option not being the default value for a CREATE
> DATABASE command, knowing that the performance is better in that case.
> --
> Olivier GIL
> LAFON SA
>
> "Russell Fields" wrote:
sql
Monday, March 26, 2012
Number of SQL Queries too large?
I'm currently in the middle of building quite a large CMS using ASP.NET and MSSQL2K and have began to question if the amount of queries I am using for one page to be built is too many?
For one page (View Forum) I am getting all of the templates and checking access then pulling a list of threads, getting the first and last posts, then user info for the first and last posts... anyway to view 10 threads on the page the number of queries comes to about 54 and the page takes 0.064 seconds to load.
My question is, Is this to many queries to be running for a single page load? All queries are using Stored Procedures.
Thanks Guys.Hi,
Since you are using StoredProcedures, performance shouldnt be bad. However 54 queries for a page is a bit high
Did you try mingling one of these procedures within the other?
Anyway, you can try creating views and writing procedures to retrive data from them incase your queries involve table joins.
indexing your tables might be another good option. These are at the SQL Level.
Hope it helps.|||thanks for your reply,
I actually did see what would happen by pulling all the data in one request using table joins and such and it actually effected performance for the worse =(
I'm not worried about performance as it is currently as fast as I could hope, was just getting concerned about the ammount of requests to the database.
Thanks for your help =)|||Hi,
Your Welcome! As long as the page is served fast, you don't have to worry :)
Because, there will be an automatic timeout, if the executing query takes too much time.
Hope it helps.
Monday, March 12, 2012
Number are displayed in the wrong format
Hi
I'm not sure if this is a .net or a SQL issue. My development machine is using SQL 2005 while the live server is SQL2000. I have a smallmoney field in the database for holding a house rent. The following is used to display the contents on the page
<asp:Label ID="lblrent" runat="server" Text='<%# Bind("rent", "(0:0.00)") %>'></asp:Label
In development, the number is displayed correctly, with the decimal place, .e.g. 200.50 but on the live server the number is displayed as 20050,00.
What I have noticed in the database is that the number is held differently
SQL 2005 - 200.5000
SQL 2000 - 20050
Is there a difference between SQL 2000 and 2005? How do I get around this problem?
Many thanks
Try using this as your formatting string. I'm not sure what would cause that problem.
{0:c}
I hope that helps,
Brendan
oops sorry do both of them list the same datatype for the column? It should be money or smallmoney for both of them. If it is not it might still have let you insert the value and now would be giving an incorrect result.
My guess would be that one of your servers is set to a culture that you aren't expecting. My guess would be the production webserver is set to a culture that uses "," as the decimal separator, and "." as the thousands separator (Considering that it printed the number 20050 as 20050,00).
|||The datatype for the columns in both databases is smallmoney, which is why I'm a bit confused as to why they are being displayed differently. Even if I manually change the entry in the SQL2000 db to a number with a decimal place, the decimal place is removed.
I tried using {0:C} as the formatstring and what I get back is 20.050,00 € on the server with SQL2000. With SQL2005 I get £200.50.
The server where the website hosted is with 1and1 using a MS Business PRO package, so I don't really have a lot of control over the SQL config. I have e-mailed tech support asking for some more information on the default settings for the SQL setup.
If I am using the same code and the same formatstring, the problem must be with the database setup. Right?
|||
No.
Put this in your web.config somewhere in the <system.web> tags:
<globalizationculture="en-US"uiCulture="en-US"/>
Now the SQL2000 server should show $20,500.00 and the SQL2005 server should show $200.50.
How did you get the data from one server to the other? Because whatever process you used also had culture problems, and the data didn't get moved correctly.
|||Thanks. That solved the problem. I changed it to en-GB, as this is a UK site and I need the £ symbol displayed. The numbers are being displayed correctly.
Only the table structure was imported to the server. No data was imported for the table with the money columns. The users are entering the data themselves.
I exported the table structure using the SQL Database Publishing Wizard. I changed the option 'script for server version' to SQL Server 2000 and left the other options at default. Should I have changed any of the other options?
Number / description of sql error
Hi
All Sql Server errors have a number. Is there any MS or MSDN website or any .net method in which I can see these errors?
Thanks a lot
switch (error.Number)
{
case 17:
msgErro =...
break;
case 4060:
msgErro =...
break;
case 18456:
msgErro = ....
break;
default:
msgErro = exSql.Message;
break;
}
Roberot,
The SQL Server error codes are in SQL Server Books On-line, which is part of the documentation that's installed with SQL Server. You may try googling "SQL Server error codes" if you don't have access to the documentation.
Good luck
|||
Roberot:
Hi
All Sql Server errors have a number. Is there any MS or MSDN website or any .net method in which I can see these errors?
Thanks a lot
switch (error.Number)
{
case 17:
msgErro =...
break;
case 4060:
msgErro =...
break;
case 18456:
msgErro = ....
break;
default:
msgErro = exSql.Message;
break;
}
Try the link below to download the BOL(books online). Hope this helps.
http://www.microsoft.com/downloads/details.aspx?FamilyID=BE6A2C5D-00DF-4220-B133-29C1E0B6585F&displaylang=en
Friday, March 9, 2012
NullReferenceException on an already instanciated object in SQL/C#
there really hasn't been the answer/help that I was expecting. Therefore I a
m
trying the thread here.
--
Hello, I have a perplexing situation. I have the following set of code, whic
h
depends on a scheduling library from GravityBox software (Schedule.NET 2005)
.
Nobody in their forums has been able to help me resolve this problem:
scheduleDomainController1.ConnectionString =
"data source=. \\SQLExpress;database=MyDatabase;Integra
ted Security=True;";
string AccountID = "00000000-0000-0000-0000-000000000000";
try
{
dataSet1 =
scheduleDomainController1.GetScheduleDataSet(AccountID);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
schedule1.DataSource = dataSet1;
schedule1.Bind();
The line above: dataSet1 =
scheduleDomainController1.GetScheduleDataSet(AccountID);
is always raising an exception: NullReferenceException.
"Object reference not set to an instance of an object"
dataSet1 is instanciated/created at runtime as well as
scheduleDomainController1.
I'm miffed here as to why I'm getting this exception. Any clues?
Thanks
MikeI don't know anything about your object, but when using datasets in VB.Net I
often get this same exception. It usually means that either no data was
returned, or there was a database error while retrieving the data.
"eljainc" <eljainc@.discussions.microsoft.com> wrote in message
news:079F346A-ED63-41DC-810B-36B563A6B3C8@.microsoft.com...
> Hi, I've posted the following message in the .NET C# MSDN newsgroup, but
> there really hasn't been the answer/help that I was expecting. Therefore I
am
> trying the thread here.
> --
> Hello, I have a perplexing situation. I have the following set of code,
which
> depends on a scheduling library from GravityBox software (Schedule.NET
2005).
> Nobody in their forums has been able to help me resolve this problem:
> scheduleDomainController1.ConnectionString =
> "data source=. \\SQLExpress;database=MyDatabase;Integra
ted Security=True;";
> string AccountID = "00000000-0000-0000-0000-000000000000";
> try
> {
> dataSet1 =
> scheduleDomainController1.GetScheduleDataSet(AccountID);
> }
> catch (Exception ex)
> {
> MessageBox.Show(ex.Message + ex.StackTrace);
> }
> schedule1.DataSource = dataSet1;
> schedule1.Bind();
>
> The line above: dataSet1 =
> scheduleDomainController1.GetScheduleDataSet(AccountID);
> is always raising an exception: NullReferenceException.
> "Object reference not set to an instance of an object"
> dataSet1 is instanciated/created at runtime as well as
> scheduleDomainController1.
> I'm miffed here as to why I'm getting this exception. Any clues?
> Thanks
> Mike|||Mike,
Can you post the complete stack trace of that exception? That would
help me determine whether the exception is generated from the current
method or from the GetScheduleDataSet method.
Brian
eljainc wrote:
> Hi, I've posted the following message in the .NET C# MSDN newsgroup, but
> there really hasn't been the answer/help that I was expecting. Therefore I
am
> trying the thread here.
> --
> Hello, I have a perplexing situation. I have the following set of code, wh
ich
> depends on a scheduling library from GravityBox software (Schedule.NET 200
5).
> Nobody in their forums has been able to help me resolve this problem:
> scheduleDomainController1.ConnectionString =
> "data source=. \\SQLExpress;database=MyDatabase;Integra
ted Security=True;";
> string AccountID = "00000000-0000-0000-0000-000000000000";
> try
> {
> dataSet1 =
> scheduleDomainController1.GetScheduleDataSet(AccountID);
> }
> catch (Exception ex)
> {
> MessageBox.Show(ex.Message + ex.StackTrace);
> }
> schedule1.DataSource = dataSet1;
> schedule1.Bind();
>
> The line above: dataSet1 =
> scheduleDomainController1.GetScheduleDataSet(AccountID);
> is always raising an exception: NullReferenceException.
> "Object reference not set to an instance of an object"
> dataSet1 is instanciated/created at runtime as well as
> scheduleDomainController1.
> I'm miffed here as to why I'm getting this exception. Any clues?
> Thanks
> Mike|||Is this sceduledomaincont1 an instance?
Juz for test
can you add this before the assignment like this?
dataSet1 = new DataSet();
dataSet1 =
> scheduleDomainController1.GetScheduleDataSet(AccountID);
--
nulled out - defaults instead?
I am converting a dbase based enterprise wide system that has almost 100
tables to convert into a vb .net system using ms sql server 2000 (I am
posting this both to ado .net newsgroups and sql server newsgroups). I am
working with a prototype where many of the columns in many of the tables
allow nulls. But often I can't call ... is null (in tsql) or isdbnull(...)
in vb .net on the same line as, say, 'or len(trim((dddd)) < 1' because this
throws an error if the col is null, since you can't measure anything when a
col is null.
Now null might have a place in the universe - like black holes - but not
being Stephen Hawkings I just don't know what that place is. But in vb .net
especially and to some extent in tsql also, it's just a pain in the ...
My question - is there any reason I shouldn't convert into tables where,
when the data is converted if it's empty or 0 (int) or # / / # (date), I
use defaults instead (eg, "", 0, 01/01/1900 respectively)? Do I lose
anything by doing this?
Tx for any help.
Bernie YaegerBernie,
Although I belong to the 'avoid nulls at all costs' camp,
you do lose something with defaults.
For example, 1/1/1900 is a valid date in many systems, so
using that date as the default will cause logical
problem. Likewise, a zero may (or may not) cause
problems when used instead of a NULL.
Think of the difference with summing a zero into an
aggregate vs taking an average. In the sum, you can
ignore the zero defaults since they are harmless, but
with the average you have to decide whether to include
them or not.
The key is how your application is coded. If you code
for defaults from the start, there are few difficulties
in making it all work smoothly since you will choose your
defaults and define how they are to be interpreted.
However, from the examples above, any code that includes
the default code in the domain of legal values can cause
you grief.
Russell Fields
>--Original Message--
>OK, I'm nulled out.
>I am converting a dbase based enterprise wide system
that has almost 100
>tables to convert into a vb .net system using ms sql
server 2000 (I am
>posting this both to ado .net newsgroups and sql server
newsgroups). I am
>working with a prototype where many of the columns in
many of the tables
>allow nulls. But often I can't call ... is null (in
tsql) or isdbnull(...)
>in vb .net on the same line as, say, 'or len(trim
((dddd)) < 1' because this
>throws an error if the col is null, since you can't
measure anything when a
>col is null.
>Now null might have a place in the universe - like black
holes - but not
>being Stephen Hawkings I just don't know what that place
is. But in vb .net
>especially and to some extent in tsql also, it's just a
pain in the ...
>My question - is there any reason I shouldn't convert
into tables where,
>when the data is converted if it's empty or 0 (int) or
# / / # (date), I
>use defaults instead (eg, "", 0, 01/01/1900
respectively)? Do I lose
>anything by doing this?
>Tx for any help.
>Bernie Yaeger
>
>.
>|||Allowing NULLS is a design decision that only you can make. IMHO, tri-state
logic is a pain because you often have to exclude data that make no logical
sense. I strongly prefer NOT NULL and default values in columns since it
simplifies the logical conditions. Just make sure your default values are
meaningful in your system and your application knows what to do with them.
NOT NULL and defaults help later when you maintain your application since
you can add columns without having to change existing code. Whatever choice
you make, apply it consistantly and document the few times when you
absolutely must deviate from the standard.
--
Geoff N. Hiten
SQL Server MVP
Senior Database Administrator
Careerbuilder.com
"Bernie Yaeger" <berniey@.cherwellinc.com> wrote in message
news:JIPZa.40432$_R5.12322590@.news4.srv.hcvlny.cv.net...
> OK, I'm nulled out.
> I am converting a dbase based enterprise wide system that has almost 100
> tables to convert into a vb .net system using ms sql server 2000 (I am
> posting this both to ado .net newsgroups and sql server newsgroups). I am
> working with a prototype where many of the columns in many of the tables
> allow nulls. But often I can't call ... is null (in tsql) or
isdbnull(...)
> in vb .net on the same line as, say, 'or len(trim((dddd)) < 1' because
this
> throws an error if the col is null, since you can't measure anything when
a
> col is null.
> Now null might have a place in the universe - like black holes - but not
> being Stephen Hawkings I just don't know what that place is. But in vb
.net
> especially and to some extent in tsql also, it's just a pain in the ...
> My question - is there any reason I shouldn't convert into tables where,
> when the data is converted if it's empty or 0 (int) or # / / # (date),
I
> use defaults instead (eg, "", 0, 01/01/1900 respectively)? Do I lose
> anything by doing this?
> Tx for any help.
> Bernie Yaeger
>|||Hi Russell,
Tx for your advice; I have considered some of the issues you raise and know
the consequences and how to deal with them, I believe.
Bernie
"Russell Fields" <rlfields@.sprynet.com> wrote in message
news:008101c36030$3efd7300$a501280a@.phx.gbl...
> Bernie,
> Although I belong to the 'avoid nulls at all costs' camp,
> you do lose something with defaults.
> For example, 1/1/1900 is a valid date in many systems, so
> using that date as the default will cause logical
> problem. Likewise, a zero may (or may not) cause
> problems when used instead of a NULL.
> Think of the difference with summing a zero into an
> aggregate vs taking an average. In the sum, you can
> ignore the zero defaults since they are harmless, but
> with the average you have to decide whether to include
> them or not.
> The key is how your application is coded. If you code
> for defaults from the start, there are few difficulties
> in making it all work smoothly since you will choose your
> defaults and define how they are to be interpreted.
> However, from the examples above, any code that includes
> the default code in the domain of legal values can cause
> you grief.
>
> Russell Fields
>
> >--Original Message--
> >OK, I'm nulled out.
> >
> >I am converting a dbase based enterprise wide system
> that has almost 100
> >tables to convert into a vb .net system using ms sql
> server 2000 (I am
> >posting this both to ado .net newsgroups and sql server
> newsgroups). I am
> >working with a prototype where many of the columns in
> many of the tables
> >allow nulls. But often I can't call ... is null (in
> tsql) or isdbnull(...)
> >in vb .net on the same line as, say, 'or len(trim
> ((dddd)) < 1' because this
> >throws an error if the col is null, since you can't
> measure anything when a
> >col is null.
> >
> >Now null might have a place in the universe - like black
> holes - but not
> >being Stephen Hawkings I just don't know what that place
> is. But in vb .net
> >especially and to some extent in tsql also, it's just a
> pain in the ...
> >
> >My question - is there any reason I shouldn't convert
> into tables where,
> >when the data is converted if it's empty or 0 (int) or
> # / / # (date), I
> >use defaults instead (eg, "", 0, 01/01/1900
> respectively)? Do I lose
> >anything by doing this?
> >
> >Tx for any help.
> >
> >Bernie Yaeger
> >
> >
> >.
> >|||With due respect to my colleagues, I fall into the 'Use Nulls when
necessary' camp... if you do not know the value, you do not know... Tri
state logic is a little more difficult, but I prefer the data to represent
reality...
And this is something where 'reasonable people differ' in their opinions...
"Bernie Yaeger" <berniey@.cherwellinc.com> wrote in message
news:JIPZa.40432$_R5.12322590@.news4.srv.hcvlny.cv.net...
> OK, I'm nulled out.
> I am converting a dbase based enterprise wide system that has almost 100
> tables to convert into a vb .net system using ms sql server 2000 (I am
> posting this both to ado .net newsgroups and sql server newsgroups). I am
> working with a prototype where many of the columns in many of the tables
> allow nulls. But often I can't call ... is null (in tsql) or
isdbnull(...)
> in vb .net on the same line as, say, 'or len(trim((dddd)) < 1' because
this
> throws an error if the col is null, since you can't measure anything when
a
> col is null.
> Now null might have a place in the universe - like black holes - but not
> being Stephen Hawkings I just don't know what that place is. But in vb
.net
> especially and to some extent in tsql also, it's just a pain in the ...
> My question - is there any reason I shouldn't convert into tables where,
> when the data is converted if it's empty or 0 (int) or # / / # (date),
I
> use defaults instead (eg, "", 0, 01/01/1900 respectively)? Do I lose
> anything by doing this?
> Tx for any help.
> Bernie Yaeger
>|||Just to clarify, I am not religiously opposed to using Nulls. I just think
the places where they apply are very few. If you have properly represented
Entity Relationships in your database, either you know about an entity or
that entity doesn't exist. Thus, you have a complete row in an appropriate
table or no row in that table.
Since most of us work in the real world where we have to live with inherited
databases, Nulls are a fact of life. I prefer to choose where I use nulls
and treat them as the exception rather than the rule. Again, this is just a
personal design preference and should not be taken as holy writ.
--
Geoff N. Hiten
SQL Server MVP
Senior Database Administrator
Careerbuilder.com
"Wayne Snyder" <wsnyder@.computeredservices.com> wrote in message
news:#63VdaLYDHA.384@.TK2MSFTNGP12.phx.gbl...
> With due respect to my colleagues, I fall into the 'Use Nulls when
> necessary' camp... if you do not know the value, you do not know... Tri
> state logic is a little more difficult, but I prefer the data to represent
> reality...
> And this is something where 'reasonable people differ' in their
opinions...
> "Bernie Yaeger" <berniey@.cherwellinc.com> wrote in message
> news:JIPZa.40432$_R5.12322590@.news4.srv.hcvlny.cv.net...
> > OK, I'm nulled out.
> >
> > I am converting a dbase based enterprise wide system that has almost 100
> > tables to convert into a vb .net system using ms sql server 2000 (I am
> > posting this both to ado .net newsgroups and sql server newsgroups). I
am
> > working with a prototype where many of the columns in many of the tables
> > allow nulls. But often I can't call ... is null (in tsql) or
> isdbnull(...)
> > in vb .net on the same line as, say, 'or len(trim((dddd)) < 1' because
> this
> > throws an error if the col is null, since you can't measure anything
when
> a
> > col is null.
> >
> > Now null might have a place in the universe - like black holes - but not
> > being Stephen Hawkings I just don't know what that place is. But in vb
> .net
> > especially and to some extent in tsql also, it's just a pain in the ...
> >
> > My question - is there any reason I shouldn't convert into tables where,
> > when the data is converted if it's empty or 0 (int) or # / / #
(date),
> I
> > use defaults instead (eg, "", 0, 01/01/1900 respectively)? Do I lose
> > anything by doing this?
> >
> > Tx for any help.
> >
> > Bernie Yaeger
> >
> >
>
Wednesday, March 7, 2012
NULL values
number in.
If they blank out the text box then I want to put a null value back into the
database field.
I want to return the value to NULL like txtWaterDischargeRate =
System.DBNull.Value instead of Nothing but I get an error
Can't convert NULL to integer
How can I enter a null in the database field on MS SQL Server?
ThanksHi
I am not sure what you are trying to do and I'm not a webform expert, but
you should be able to set may want to try something like checking the field'
s
data length in the application and passing DBNULL.value to the stored
procedure.
Alternatively you may be able to use a special value (say -1) and use
NULLIF(@.parameter,-1) in your insert statement.
John
"Craig" wrote:
> I have a text box on a web form in visual studio.net that a user enters a
> number in.
> If they blank out the text box then I want to put a null value back into t
he
> database field.
> I want to return the value to NULL like txtWaterDischargeRate =
> System.DBNull.Value instead of Nothing but I get an error
> Can't convert NULL to integer
> How can I enter a null in the database field on MS SQL Server?
> Thanks
>
>
>|||Sample code.....
With DataSetLocationsForm1.tblLocations(0)
.WaterDischargeCost = txtWaterDischargeCost.Text
.MoreFields = txtOtherTextboxes.Text
End With
SqlDataAdapter1.Update(DataSetLocationsForm1)
The WaterDischargeCost field in the database is an type real. If they blank
out the text box and click the SAVE button on an existing record I get an
error "Can't convert NULL to integer"
I want to put a null value back into the database field
How do I do this?
Thanks
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...[vbcol=seagreen]
> Hi
> I am not sure what you are trying to do and I'm not a webform expert, but
> you should be able to set may want to try something like checking the
> field's
> data length in the application and passing DBNULL.value to the stored
> procedure.
> Alternatively you may be able to use a special value (say -1) and use
> NULLIF(@.parameter,-1) in your insert statement.
> John
> "Craig" wrote:
>|||Hi Craig,
Thanks for your post.
From your descriptions, I understood you would like to know how to how to
handle NULL with SQL Server in VS.NET. If I have misunderstood your
concern, please feel free to point it out.
To better answer this question, I would recommand you raise the question in
ADO.NET or VS.NET managed newsgroup.
microsoft.public.dotnet.framework.adonet
microsoft.public.dotnet.framework
Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are always here to be of
assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi
This is almost certainly because you are passing as string "NULL" and not
NULL itself.
Try something like (although the syntax may not be correct!)
IF txtWaterDischargeCost.length > 0
.WaterDischargeCost = txtWaterDischargeCost.Text
ELSE
.WaterDischargeCost = System.DBNull
You can use SQL profiler to see the SQL statement sent to the database and
verify what the command actually is.
John
"Craig" wrote:
> Sample code.....
> With DataSetLocationsForm1.tblLocations(0)
> .WaterDischargeCost = txtWaterDischargeCost.Text
> .MoreFields = txtOtherTextboxes.Text
> End With
> SqlDataAdapter1.Update(DataSetLocationsForm1)
> The WaterDischargeCost field in the database is an type real. If they blan
k
> out the text box and click the SAVE button on an existing record I get an
> error "Can't convert NULL to integer"
> I want to put a null value back into the database field
> How do I do this?
> Thanks
>
>
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...
>
>|||If the column WaterDischargeCost is nullable (minoccurs = 0), then you can
use:
DataSetLocationsForm1.tblLocations(0).SetWaterDischargeCostNull()
to let the dataset set the value as null.
This works!!!!
"Craig" <NoSpam@.hotmail.com> wrote in message
news:O6UVrbCqFHA.3160@.TK2MSFTNGP14.phx.gbl...
> Sample code.....
> With DataSetLocationsForm1.tblLocations(0)
> .WaterDischargeCost = txtWaterDischargeCost.Text
> .MoreFields = txtOtherTextboxes.Text
> End With
> SqlDataAdapter1.Update(DataSetLocationsForm1)
> The WaterDischargeCost field in the database is an type real. If they
> blank out the text box and click the SAVE button on an existing record I
> get an error "Can't convert NULL to integer"
> I want to put a null value back into the database field
> How do I do this?
> Thanks
>
>
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...
>
NULL values
number in.
If they blank out the text box then I want to put a null value back into the
database field.
I want to return the value to NULL like txtWaterDischargeRate = System.DBNull.Value instead of Nothing but I get an error
Can't convert NULL to integer
How can I enter a null in the database field on MS SQL Server?
ThanksHi
I am not sure what you are trying to do and I'm not a webform expert, but
you should be able to set may want to try something like checking the field's
data length in the application and passing DBNULL.value to the stored
procedure.
Alternatively you may be able to use a special value (say -1) and use
NULLIF(@.parameter,-1) in your insert statement.
John
"Craig" wrote:
> I have a text box on a web form in visual studio.net that a user enters a
> number in.
> If they blank out the text box then I want to put a null value back into the
> database field.
> I want to return the value to NULL like txtWaterDischargeRate => System.DBNull.Value instead of Nothing but I get an error
> Can't convert NULL to integer
> How can I enter a null in the database field on MS SQL Server?
> Thanks
>
>
>|||Sample code.....
With DataSetLocationsForm1.tblLocations(0)
.WaterDischargeCost = txtWaterDischargeCost.Text
.MoreFields = txtOtherTextboxes.Text
End With
SqlDataAdapter1.Update(DataSetLocationsForm1)
The WaterDischargeCost field in the database is an type real. If they blank
out the text box and click the SAVE button on an existing record I get an
error "Can't convert NULL to integer"
I want to put a null value back into the database field
How do I do this?
Thanks
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...
> Hi
> I am not sure what you are trying to do and I'm not a webform expert, but
> you should be able to set may want to try something like checking the
> field's
> data length in the application and passing DBNULL.value to the stored
> procedure.
> Alternatively you may be able to use a special value (say -1) and use
> NULLIF(@.parameter,-1) in your insert statement.
> John
> "Craig" wrote:
>> I have a text box on a web form in visual studio.net that a user enters a
>> number in.
>> If they blank out the text box then I want to put a null value back into
>> the
>> database field.
>> I want to return the value to NULL like txtWaterDischargeRate =>> System.DBNull.Value instead of Nothing but I get an error
>> Can't convert NULL to integer
>> How can I enter a null in the database field on MS SQL Server?
>> Thanks
>>
>>|||Hi Craig,
Thanks for your post.
From your descriptions, I understood you would like to know how to how to
handle NULL with SQL Server in VS.NET. If I have misunderstood your
concern, please feel free to point it out.
To better answer this question, I would recommand you raise the question in
ADO.NET or VS.NET managed newsgroup.
microsoft.public.dotnet.framework.adonet
microsoft.public.dotnet.framework
Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are always here to be of
assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi
This is almost certainly because you are passing as string "NULL" and not
NULL itself.
Try something like (although the syntax may not be correct!)
IF txtWaterDischargeCost.length > 0
.WaterDischargeCost = txtWaterDischargeCost.Text
ELSE
.WaterDischargeCost = System.DBNull
You can use SQL profiler to see the SQL statement sent to the database and
verify what the command actually is.
John
"Craig" wrote:
> Sample code.....
> With DataSetLocationsForm1.tblLocations(0)
> .WaterDischargeCost = txtWaterDischargeCost.Text
> .MoreFields = txtOtherTextboxes.Text
> End With
> SqlDataAdapter1.Update(DataSetLocationsForm1)
> The WaterDischargeCost field in the database is an type real. If they blank
> out the text box and click the SAVE button on an existing record I get an
> error "Can't convert NULL to integer"
> I want to put a null value back into the database field
> How do I do this?
> Thanks
>
>
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...
> > Hi
> >
> > I am not sure what you are trying to do and I'm not a webform expert, but
> > you should be able to set may want to try something like checking the
> > field's
> > data length in the application and passing DBNULL.value to the stored
> > procedure.
> >
> > Alternatively you may be able to use a special value (say -1) and use
> > NULLIF(@.parameter,-1) in your insert statement.
> >
> > John
> >
> > "Craig" wrote:
> >
> >> I have a text box on a web form in visual studio.net that a user enters a
> >> number in.
> >>
> >> If they blank out the text box then I want to put a null value back into
> >> the
> >> database field.
> >>
> >> I want to return the value to NULL like txtWaterDischargeRate => >> System.DBNull.Value instead of Nothing but I get an error
> >>
> >> Can't convert NULL to integer
> >>
> >> How can I enter a null in the database field on MS SQL Server?
> >>
> >> Thanks
> >>
> >>
> >>
> >>
> >>
>
>|||If the column WaterDischargeCost is nullable (minoccurs = 0), then you can
use:
DataSetLocationsForm1.tblLocations(0).SetWaterDischargeCostNull()
to let the dataset set the value as null.
This works!!!!
"Craig" <NoSpam@.hotmail.com> wrote in message
news:O6UVrbCqFHA.3160@.TK2MSFTNGP14.phx.gbl...
> Sample code.....
> With DataSetLocationsForm1.tblLocations(0)
> .WaterDischargeCost = txtWaterDischargeCost.Text
> .MoreFields = txtOtherTextboxes.Text
> End With
> SqlDataAdapter1.Update(DataSetLocationsForm1)
> The WaterDischargeCost field in the database is an type real. If they
> blank out the text box and click the SAVE button on an existing record I
> get an error "Can't convert NULL to integer"
> I want to put a null value back into the database field
> How do I do this?
> Thanks
>
>
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...
>> Hi
>> I am not sure what you are trying to do and I'm not a webform expert, but
>> you should be able to set may want to try something like checking the
>> field's
>> data length in the application and passing DBNULL.value to the stored
>> procedure.
>> Alternatively you may be able to use a special value (say -1) and use
>> NULLIF(@.parameter,-1) in your insert statement.
>> John
>> "Craig" wrote:
>> I have a text box on a web form in visual studio.net that a user enters
>> a
>> number in.
>> If they blank out the text box then I want to put a null value back into
>> the
>> database field.
>> I want to return the value to NULL like txtWaterDischargeRate =>> System.DBNull.Value instead of Nothing but I get an error
>> Can't convert NULL to integer
>> How can I enter a null in the database field on MS SQL Server?
>> Thanks
>>
>>
>
Saturday, February 25, 2012
NULL values
number in.
If they blank out the text box then I want to put a null value back into the
database field.
I want to return the value to NULL like txtWaterDischargeRate =
System.DBNull.Value instead of Nothing but I get an error
Can't convert NULL to integer
How can I enter a null in the database field on MS SQL Server?
Thanks
Hi
I am not sure what you are trying to do and I'm not a webform expert, but
you should be able to set may want to try something like checking the field's
data length in the application and passing DBNULL.value to the stored
procedure.
Alternatively you may be able to use a special value (say -1) and use
NULLIF(@.parameter,-1) in your insert statement.
John
"Craig" wrote:
> I have a text box on a web form in visual studio.net that a user enters a
> number in.
> If they blank out the text box then I want to put a null value back into the
> database field.
> I want to return the value to NULL like txtWaterDischargeRate =
> System.DBNull.Value instead of Nothing but I get an error
> Can't convert NULL to integer
> How can I enter a null in the database field on MS SQL Server?
> Thanks
>
>
>
|||Sample code.....
With DataSetLocationsForm1.tblLocations(0)
.WaterDischargeCost = txtWaterDischargeCost.Text
.MoreFields = txtOtherTextboxes.Text
End With
SqlDataAdapter1.Update(DataSetLocationsForm1)
The WaterDischargeCost field in the database is an type real. If they blank
out the text box and click the SAVE button on an existing record I get an
error "Can't convert NULL to integer"
I want to put a null value back into the database field
How do I do this?
Thanks
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...[vbcol=seagreen]
> Hi
> I am not sure what you are trying to do and I'm not a webform expert, but
> you should be able to set may want to try something like checking the
> field's
> data length in the application and passing DBNULL.value to the stored
> procedure.
> Alternatively you may be able to use a special value (say -1) and use
> NULLIF(@.parameter,-1) in your insert statement.
> John
> "Craig" wrote:
|||Hi Craig,
Thanks for your post.
From your descriptions, I understood you would like to know how to how to
handle NULL with SQL Server in VS.NET. If I have misunderstood your
concern, please feel free to point it out.
To better answer this question, I would recommand you raise the question in
ADO.NET or VS.NET managed newsgroup.
microsoft.public.dotnet.framework.adonet
microsoft.public.dotnet.framework
Thank you for your patience and cooperation. If you have any questions or
concerns, don't hesitate to let me know. We are always here to be of
assistance!
Sincerely yours,
Michael Cheng
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.
|||Hi
This is almost certainly because you are passing as string "NULL" and not
NULL itself.
Try something like (although the syntax may not be correct!)
IF txtWaterDischargeCost.length > 0
..WaterDischargeCost = txtWaterDischargeCost.Text
ELSE
..WaterDischargeCost = System.DBNull
You can use SQL profiler to see the SQL statement sent to the database and
verify what the command actually is.
John
"Craig" wrote:
> Sample code.....
> With DataSetLocationsForm1.tblLocations(0)
> .WaterDischargeCost = txtWaterDischargeCost.Text
> .MoreFields = txtOtherTextboxes.Text
> End With
> SqlDataAdapter1.Update(DataSetLocationsForm1)
> The WaterDischargeCost field in the database is an type real. If they blank
> out the text box and click the SAVE button on an existing record I get an
> error "Can't convert NULL to integer"
> I want to put a null value back into the database field
> How do I do this?
> Thanks
>
>
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...
>
>
|||If the column WaterDischargeCost is nullable (minoccurs = 0), then you can
use:
DataSetLocationsForm1.tblLocations(0).SetWaterDisc hargeCostNull()
to let the dataset set the value as null.
This works!!!!
"Craig" <NoSpam@.hotmail.com> wrote in message
news:O6UVrbCqFHA.3160@.TK2MSFTNGP14.phx.gbl...
> Sample code.....
> With DataSetLocationsForm1.tblLocations(0)
> .WaterDischargeCost = txtWaterDischargeCost.Text
> .MoreFields = txtOtherTextboxes.Text
> End With
> SqlDataAdapter1.Update(DataSetLocationsForm1)
> The WaterDischargeCost field in the database is an type real. If they
> blank out the text box and click the SAVE button on an existing record I
> get an error "Can't convert NULL to integer"
> I want to put a null value back into the database field
> How do I do this?
> Thanks
>
>
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:9FE6B6DA-00CE-448A-A740-2E950BC1AC57@.microsoft.com...
>
NULL to Zero
view that need to calculate the net inventory by subtracting the export qty
from import qty. However, in case of no export, 1-Null=Null. Thanks.[posted and mailed, please reply in news]
John Q (johnq@.hkayp.org) writes:
> Is there any function that would change a NULL value to zero? I am
> writing a view that need to calculate the net inventory by subtracting
> the export qty from import qty. However, in case of no export,
> 1-Null=Null. Thanks.
coalesce(val1, val2, ..., valn)
returns the first non-NULL value in the list.
(There is also a function isnull() which has a clearer name, but is
restricted to two parameters only. coalesce() is from the ANSI standard.)
--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Erland,
Thank you very much. This function is very useful to me.
Best Regards,
Frederick
"Erland Sommarskog" <sommar@.algonet.se> bl
news:Xns93EC5BCD76E8Yazorman@.127.0.0.1 g...
> [posted and mailed, please reply in news]
> John Q (johnq@.hkayp.org) writes:
> > Is there any function that would change a NULL value to zero? I am
> > writing a view that need to calculate the net inventory by subtracting
> > the export qty from import qty. However, in case of no export,
> > 1-Null=Null. Thanks.
> coalesce(val1, val2, ..., valn)
> returns the first non-NULL value in the list.
> (There is also a function isnull() which has a clearer name, but is
> restricted to two parameters only. coalesce() is from the ANSI standard.)
>
> --
> Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techin.../2000/books.asp
NULL SQL 2000
I made a small ASP.NET (C#) site on my local machine that connects to SQL 2000. When I test the application it runs great. Everything gets stored into the database and the tables that it is suppose to.
I upload the site to a hosting company and when I run it, I get all sorts of error with the database. (I also copied the database from my local machine to the server via Enterprise Manager.)
For example, when I run the registration page - I get the error message:
"Cannot insert the value NULL into column 'user_id', table 'xxx.xxxx.tbl_users'; column does not allow nulls. INSERT fails. The statement has been terminated. "
I checked the table properties and my columns are set to allow null values. With the exception of having a primary key set to a column for indentity purpose (user_id).
The weird part is that I checked to see if the data are being stored into the column... and it is! Everything that was sent from the form is being stored into the table.
So I don't understand the problem I am having. Can anyone shed some light for me?
Below is the function I've written that inserts the data into the table.
===========================
C# Function to insert data
===========================
// Store Data to String
string strFirst = reg_fname.Text.ToString().Trim();
string strLast = reg_lname.Text.ToString().Trim();
string strEmail = reg_email.Text.ToString().Trim();
string strZip = reg_zip.Text.ToString().Trim();
string strCountry = reg_country.Text.ToString().Trim();
// Open Connection to Database
string strConnection = ConfigurationSettings.AppSettings["xxxxx"];
string strSQL = "INSERT INTO tbl_registration (first_name, last_name, email, zip, country) VALUES ('"+ strFirst.Replace("'", "") +"', '"+ strLast.Replace("'", "") +"', '"+ strEmail.Replace("'", "") +"', '"+ strPassword.Replace("'", "") +"', '"+ strZip.Replace("'", "") +"', '"+ strCountry.Replace("'", "") +"')";
// Execute Connection and INSERT Data
SqlConnection oConnection = new SqlConnection(strConnection);
oConnection.Open();
SqlCommand oCommand = new SqlCommand(strSQL, oConnection )oCommand.ExecuteNonQuery();
oConnection.Close();How is the user_id column populated? You mentioned "identity purposes." Is the column marked as an IDENTITY in SQL?
Regarding your command, consider using parameterized commands:
string sqlStmt;
SqlCommand cmd;sqlStmt = "INSERT INTO (first_name, last_name, email, zip, country) VALUES (@.first_name, @.last_name, @.email, @.zip, @.country)";
cmd = new SqlCommand(sqlStmt, oConnection);
cmd.Parameters.Add("@.first_name", strFirst);
cmd.Parameters.Add("@.last_name", strLast);
cmd.Parameters.Add("@.email", strPassword);
cmd.Parameters.Add("@.zip", strZip);
cmd.Parameters.Add("@.country", strCountry);
cmd.ExecuteNonQuery();
Note that if any of the parameters contain any illegal characters, such as a single quote, the parameter will be "fixed", so the str.Replace("''", "'") is not required.|||Also, are there triggers involved? Sometimes, the error message is referring to something that your trigger was trying to do, and not the proc you were explicitly executing... :)