Showing posts with label null. Show all posts
Showing posts with label null. Show all posts

Thursday, March 22, 2012

calculated field in SQL 2000

I need a calculated field C with several CASES.
If (field A is 'daily' or 'half day' or 'hourly') and (field B is NULL) then C= D-50
If (field A is hourly and field B is NULL then C= 850
I don't know sql server 2000 well enough to create this query.
thanks
Milton

Are you trying to create a calculated column in a table or you need a SELECT query with this calculation?

|||

I need a SELECT query or view.

thanks
Milton

|||

Check out the CASE statement in Books On Line. Its pretty much self explanatory. They have illustrated it with some sample code too.

|||

I need to know the web site. I looked up books on line and found many sites with that URL. booksonline, books-on-line etc. none that I looked through were free and non had sql 2000.

|||

Here.. Its absolutely free..http://technet.microsoft.com/en-us/sqlserver/bb428874.aspx check the language you want to download it in on the right..

|||

miltonsnider:

I need a calculated field C with several CASES.
If (field A is 'daily' or 'half day' or 'hourly') and (field B is NULL) then C= D-50
If (field A is hourly and field B is NULL then C= 850
I don't know sql server 2000 well enough to create this query.
thanks
Milton

give it a try as start...

SELECT CASE WHEN (A LIKE 'hourly' AND B IS NULL) THEN 850 -- If (field A is hourly and field B is NULL then C= 850
WHEN (A LIKE 'daily' OR A LIKE 'half day' OR A LIKE 'hourly') AND (B IS NULL) THEN D - 50 END--If (field A is 'daily' or 'half day' or 'hourly') and (field B is NULL) then C= D-50
AS 'C'
FROM TBL_TABLE1

(without Comment)

SELECT CASE WHEN (A LIKE 'hourly' AND B IS NULL) THEN 850
WHEN (A LIKE 'daily' OR A LIKE 'half day' OR A LIKE 'hourly') AND (B IS NULL) THEN D - 50 END
AS 'C'
FROM TBL_TABLE1

hope you get some idea...

Wednesday, March 7, 2012

Cache Dependency Problem

Hello.

I am having problems with SQL Cache dependency. I am using SQL 2005, ASP .net 2.0.

Every time i try to load data from cache, this is null. It acts like someone is constantly changing everything in the db.

Because of this my website makes hundreds of connections to the db instead of 5. This is a major issue that i cannot figure it out. PLEASE ADVISE.

On my local machine everything seems to work just fine. On the testing server the cache is always null.

Is cache dependency related

- to the platform used?

- to the number of IIS servers connected to the DB?

- to the sql user used?

Also a strange thing happens. When i change something in web.config the cache is working for about 1 min and after that it stops.

Here is the code i wrote:

public ManufacturerList GetAllManufacturers()
{
if (HttpContext.Current.Cache[ConstantsManager.Instance.GetDefaultAsString("CACHE_MANUFACTURERS")] != null)
return HttpContext.Current.Cache[ConstantsManager.Instance.GetDefaultAsString("CACHE_MANUFACTURERS")] as ManufacturerList;

SqlCacheDependency dep = new SqlCacheDependency(ConstantsManager.Instance.GetDefaultAsString("DB_NAME"), ConstantsManager.Instance.GetDefaultAsString("TABLE_MANUFACTURERS"));

_manufacturerList = new ManufacturerList();

DataReader reader = SqlHelper.ExecuteDataReader(WebContext.ConnectionString, CommandType.StoredProcedure, "dvx_web_MANUFACTURER_LoadAll", null);

while (reader.Read())
{
int manufacturerID = reader.GetInt("ID");

Manufacturer findManufacturer = _manufacturerList.FindByID(manufacturerID);

if (findManufacturer == null)
{
findManufacturer = new Manufacturer();
findManufacturer.LoadFromDataReader(reader);
_manufacturerList.Add(findManufacturer);
}
}

reader.Close();

HttpContext.Current.Cache.Insert(ConstantsManager.Instance.GetDefaultAsString("CACHE_MANUFACTURERS"), _manufacturerList, dep);

return _manufacturerList;
}

Thanks a lot.

Hi,

Look at this article describing some ways of using SQL Dependency Cache.

http://www.ondotnet.com/pub/a/dotnet/2005/01/17/sqlcachedependency.html

Friday, February 24, 2012

C# web app connection to SQL 2000

Hello, everyone,
I am trying to connect to a SQL server db with a C# app and when I debug I
get:
Login failed for user '(null)'. Reason: Not associated with a trusted SQL
Server connection.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user
'(null)'. Reason: Not associated with a trusted SQL Server connection.
Source Error:
Line 27: if (!Page.IsPostBack)
Line 28: {
Line 29: sqlDataAdapter1.Fill(dsStudents1);
Line 30: DataGrid1.DataBind();
Line 31: }
Can somebody give me any suggestions?
Thanks,
Antonio
You are probably using the key word Integrated Security=SSPI or
trusted_connection=yes in your connection string and your Windows credential
(i.e. that of the login that runs the program) has not been granted access to
the SQL Server instance.
I'd first change Integrated Security=SSPI to user=myUser;pwd=myPassword, and
verify that there is no problem with connectivity itself (and there shouldn't
be any per your error message). Then, grant the Windows login access to the
SQL Server instance, and now you can use Integrated Security=SSPI.
Linchi
"Antonio" wrote:

> Hello, everyone,
> I am trying to connect to a SQL server db with a C# app and when I debug I
> get:
> Login failed for user '(null)'. Reason: Not associated with a trusted SQL
> Server connection.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
> Exception Details: System.Data.SqlClient.SqlException: Login failed for user
> '(null)'. Reason: Not associated with a trusted SQL Server connection.
> Source Error:
>
> Line 27: if (!Page.IsPostBack)
> Line 28: {
> Line 29: sqlDataAdapter1.Fill(dsStudents1);
> Line 30: DataGrid1.DataBind();
> Line 31: }
>
> Can somebody give me any suggestions?
> Thanks,
>
> Antonio
>
>
|||You need to grant access to ASPNET user to your database. That is the
account that web application use.
"Antonio" <info@.awfulcards.com> wrote in message
news:uMqrFT2SGHA.5884@.TK2MSFTNGP14.phx.gbl...
> Hello, everyone,
> I am trying to connect to a SQL server db with a C# app and when I debug I
> get:
> Login failed for user '(null)'. Reason: Not associated with a trusted SQL
> Server connection.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
> Exception Details: System.Data.SqlClient.SqlException: Login failed for
> user '(null)'. Reason: Not associated with a trusted SQL Server
> connection.
> Source Error:
>
> Line 27: if (!Page.IsPostBack)
> Line 28: {
> Line 29: sqlDataAdapter1.Fill(dsStudents1);
> Line 30: DataGrid1.DataBind();
> Line 31: }
>
> Can somebody give me any suggestions?
> Thanks,
>
> Antonio
>
|||The ASPNET user is setup in the database (the ASPNET user in the server, not
my machine) with access to the specific database, as owner.
"Shimon Sim" wrote:

> You need to grant access to ASPNET user to your database. That is the
> account that web application use.
> "Antonio" <info@.awfulcards.com> wrote in message
> news:uMqrFT2SGHA.5884@.TK2MSFTNGP14.phx.gbl...
>
>
|||What is your connection string?
It is strange that user is '(null)'.
"Antonio" <Antonio@.discussions.microsoft.com> wrote in message
news:35ADEC88-2C2A-45AB-BFD9-C86607839493@.microsoft.com...[vbcol=seagreen]
> The ASPNET user is setup in the database (the ASPNET user in the server,
> not
> my machine) with access to the specific database, as owner.
> "Shimon Sim" wrote:
|||Didi you grant the appropiate rights to the service account which
starts the worker process (on *your* computer) on the SQL Server ?
Domain\ServiceAccount (Your Computer) -- > has to be prviledged on the
SQL Server
Make sure that you didn=B4t accept anonymous authentication on your
webserver.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de

C# web app connection to SQL 2000

Hello, everyone,
I am trying to connect to a SQL server db with a C# app and when I debug I
get:
Login failed for user '(null)'. Reason: Not associated with a trusted SQL
Server connection.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user
'(null)'. Reason: Not associated with a trusted SQL Server connection.
Source Error:
Line 27: if (!Page.IsPostBack)
Line 28: {
Line 29: sqlDataAdapter1.Fill(dsStudents1);
Line 30: DataGrid1.DataBind();
Line 31: }
Can somebody give me any suggestions?
Thanks,
AntonioYou are probably using the key word Integrated Security=SSPI or
trusted_connection=yes in your connection string and your Windows credential
(i.e. that of the login that runs the program) has not been granted access t
o
the SQL Server instance.
I'd first change Integrated Security=SSPI to user=myUser;pwd=myPassword, and
verify that there is no problem with connectivity itself (and there shouldn'
t
be any per your error message). Then, grant the Windows login access to the
SQL Server instance, and now you can use Integrated Security=SSPI.
Linchi
"Antonio" wrote:

> Hello, everyone,
> I am trying to connect to a SQL server db with a C# app and when I debug I
> get:
> Login failed for user '(null)'. Reason: Not associated with a trusted SQL
> Server connection.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
> Exception Details: System.Data.SqlClient.SqlException: Login failed for us
er
> '(null)'. Reason: Not associated with a trusted SQL Server connection.
> Source Error:
>
> Line 27: if (!Page.IsPostBack)
> Line 28: {
> Line 29: sqlDataAdapter1.Fill(dsStudents1);
> Line 30: DataGrid1.DataBind();
> Line 31: }
>
> Can somebody give me any suggestions?
> Thanks,
>
> Antonio
>
>|||You need to grant access to ASPNET user to your database. That is the
account that web application use.
"Antonio" <info@.awfulcards.com> wrote in message
news:uMqrFT2SGHA.5884@.TK2MSFTNGP14.phx.gbl...
> Hello, everyone,
> I am trying to connect to a SQL server db with a C# app and when I debug I
> get:
> Login failed for user '(null)'. Reason: Not associated with a trusted SQL
> Server connection.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
> Exception Details: System.Data.SqlClient.SqlException: Login failed for
> user '(null)'. Reason: Not associated with a trusted SQL Server
> connection.
> Source Error:
>
> Line 27: if (!Page.IsPostBack)
> Line 28: {
> Line 29: sqlDataAdapter1.Fill(dsStudents1);
> Line 30: DataGrid1.DataBind();
> Line 31: }
>
> Can somebody give me any suggestions?
> Thanks,
>
> Antonio
>|||The ASPNET user is setup in the database (the ASPNET user in the server, not
my machine) with access to the specific database, as owner.
"Shimon Sim" wrote:

> You need to grant access to ASPNET user to your database. That is the
> account that web application use.
> "Antonio" <info@.awfulcards.com> wrote in message
> news:uMqrFT2SGHA.5884@.TK2MSFTNGP14.phx.gbl...
>
>|||What is your connection string?
It is strange that user is '(null)'.
"Antonio" <Antonio@.discussions.microsoft.com> wrote in message
news:35ADEC88-2C2A-45AB-BFD9-C86607839493@.microsoft.com...[vbcol=seagreen]
> The ASPNET user is setup in the database (the ASPNET user in the server,
> not
> my machine) with access to the specific database, as owner.
> "Shimon Sim" wrote:
>|||Didi you grant the appropiate rights to the service account which
starts the worker process (on *your* computer) on the SQL Server ?
Domain\ServiceAccount (Your Computer) -- > has to be prviledged on the
SQL Server
Make sure that you didn=B4t accept anonymous authentication on your
webserver.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--

C# Parameterized Query with null values

Hello.
I have (2) related questions.
#1: I am using a paramterized query, but am unable to make it work if one of the values happens to be null.
if (Request.Form["txtLink1"] != "")
{
mySqlCmd.Parameters.Add(new SqlParameter("@.link1",SqlDbType.VarChar));
mySqlCmd.Parameters["@.link1"].Value =Request.Form["txtLink1"];
}
else
{
mySqlCmd.Parameters.Add(new SqlParameter("@.link1",SqlDbType.VarChar));
mySqlCmd.Parameters["@.link1"].Value = null;
}
If txtLink1 happens to be empty, I want @.link1 to enter null. Thecolumn in the Sql Server allows for nulls, but I get an error messagethat says no value was supplied. In short, how do I supply a null valueusing a parameterized query?
#2: For debugging purposes, how can I view what my SQL string lookslike (with all the values entered) before it gets submitted to thedatabase? When I view the string, it still contains the placeholdervalues (@.link1) instead of the actual values.
Thanks in advance!
-Brenden
(1) You dont have to be redundant in declaring the variable twice. You could move the line

mySqlCmd.Parameters.Add(new SqlParameter("@.link1", SqlDbType.VarChar));

out of your IF loop. as in :

mySqlCmd.Parameters.Add(new SqlParameter("@.link1", SqlDbType.VarChar));
if (Request.Form["txtLink1"] != "")
{
mySqlCmd.Parameters["@.link1"].Value = Request.Form["txtLink1"];
}
else
{
mySqlCmd.Parameters["@.link1"].Value =Dbnull.Value;
}
(2) and use DbNull.Value for nulls.
(3) You might also want to add in the size of the parameter to avoid issues later.
mySqlCmd.Parameters.Add(new SqlParameter("@.link1", SqlDbType.VarChar,100));|||ThanksDinakar!
That solved my issue.
Much appreciated.