ADO.NET 2.0 - Three-tier application - connection string error - SQL store procedure

Using ASP.NET 2.0 beta, VS2005 beta 1, W2k3 server with IIS

I try to build a three-tier app structure as followed:
- the store procedure in SQL with a input parameter as Username and retrieve the UserId as output parameter.
- the business logic (class) with connection string defined in web.config (“AppConnectionStringASPNETapp”)
- the presentation aspx file after the user has logged in through login.aspx
I have work out 2 scenarios with 2 different errors.
Scenario 1:
Here is the code is business logic (class) (catalog.cs)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;
public class catalog
{
public static string GetUserId2(string UserName)
{
string UserId;
SqlConnection mcon = null;
SqlCommand mcmd = null;
string conString;
conString = ConfigurationSettings.AppSettings["AppConnectionStringASPNETapp"];
using (mcon = new SqlConnection(conString))
{
mcmd = new SqlCommand("aspnet_Users_GetUserIdByUserName", mcon);
mcmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm;
prm = mcmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 256);
prm.Value = UserName;
prm = mcmd.Parameters.Add("@UserId", SqlDbType.UniqueIdentifier, 16);
prm.Direction = ParameterDirection.ReturnValue;
mcon.Open();
mcmd.ExecuteNonQuery();
mcon.Close();

UserId = (string)mcmd.Parameters["@UserId"].Value;
return UserId;
}
}
}
--------------------------------------------------------------------
Here is the newimage.aspx file (code-behind)
The file includes two labels. The first retrieves the current username after the page has been logged in.
The second label is the UserId which I try to retrieve from SQL db (through a store procedure)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;
public partial class NewImage_aspx
{
void Page_Load(object sender, EventArgs e)
{

string conString;
conString = ConfigurationSettings.AppSettings["AppConnectionStringASPNETapp"];
SqlConnection mcon = new SqlConnection(conString);
labelUserName.Text = User.Identity.Name;
labelUserId.Text = catalog.GetUserId2(User.Identity.Name);
}
}
------------------------------
HTML file

<asp:Label ID="labelUserName" Runat="server"></asp:Label>
<asp:Label ID="labelUserId" Runat="server"></asp:Label>

After hitting F5, here is the error message.
The ConnectionString property has not been initialized.
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.InvalidOperationException: The ConnectionString property has not been initialized.
Source Error:
Line 51: //mcmd.Parameters.Add(prm);
Line 52:
Line 53: mcon.Open();
Line 54: mcmd.ExecuteNonQuery();
Line 55: mcon.Close();


Scenario 2
So I figure that I add the following code in my class (catalog.cs)

public class catalog
{
public string conString
{
get
{
return ConfigurationSettings.AppSettings();
}
}
public static string GetUserId2(string UserName)
{
string UserId;
SqlConnection mcon = null;
SqlCommand mcmd = null;
…….
Then I get this following error when I hit F5,
‘System.Configuration.ConfigurationSettings.AppSettings' is a 'property' but is used like a 'method' J:\WebAlbum\Code\catalog.cs
(which refers to conString line in my class).

If you any hints, please reply here or email to me at ntgraph@yahoo.com
Thanks.
0
ntgraph
12/11/2004 2:21:24 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
885 Views

Similar Articles

[PageSpeed] 59

Make user the AppConnectionStringASPNETapp is added to the <appSettings> section in the configuration file. You can know use the new ConnectionStrings section in the configuration file to add your connection strings, and use the ConntectionStings property of the ConfigurationSettigns class:


<connectionStrings>
<add name="AppConnectionStringASPNETapp" connectionString="Data Source=&quot;(local)&quot;;Initial Catalog=Northwind;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>


string conString = ConfigurationSettings.ConnectionStrings["AppConnectionStringASPNETapp"].ConnectionString;

>return ConfigurationSettings.AppSettings();
This will not work because the AppSettings is not an method, is a property, and you also have to specify which settings you want to get by using the indexer:
ConfigurationSettings.AppSettings["myKey"]

/Fredrik Normén - fredrikn @ twitter

Microsoft MVP, MCSD, MCAD, MCT

ASPInsiders
My Blog
0
Fredrik
12/11/2004 11:43:28 PM
Reply:

Similar Artilces:

.Net 2.0 Web application using Vb.net is unable to create object of another dll writen in C# .net 2.0
Hi, I habe created one ASP.net web application using Vb.net which is adding reference of dlls written in C# and .net 2.0. But whenever trying to create object of referencing dll, it is throwing error :Object reference does not set to an object. But, locally it is working fine,. In the server i have deployed the .aspx files and dll files in the bin. There were already an web.config in the server which is of .net 1.1. But checked it is retrieving value for that web.config correctly. Should i have to deply any other files and if not what can be the solution for this? Please help. Thanks, So...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0 #2
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! There are too many differences for one email - - from 1.0 to 1.1 (not a whole lot of real change, other than fixes, at least compared to 1.1 to 2.0) With 2.0, there were many new declarative controls, with many new ideas added in With 3.0, it's a superset of 2.0 - instead of replacing the installation completely, it just 'added on' new functionality - I would...

Access .Net 2.0 Application from .Net 2.0 Web Site
I need to populate a specific form in a .Net desktop application from a .net web application.  Is there an easy way to go about this? Hi, Based on my understanding, you want to start an executable application from your ASP.NET websit, right? We can invoke Process.Start method (http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx) to launch an executable application from ASP.NET application. Note: Please keep in mind, the ASP.NET application is running on the server, so it will start the executable application that exists in the server.   I look...

Where is the ADO.NET Sybase driver for .NET 1.1 and .Net 2.0?
Hi All Does anyone know where I can get the Sybase drivers for ADO.NET for both versions, 1.1 and 2.0/3.0? Cheers Chris Burrell Hi Chris, There is no release of ASE ADO.NET Provider 2.0 (I assume you refer to ASE provider, not ASA - if ASA please port to sybase.public.sqlanywhere.general). For the 1.1 Provider: It is available in the ASE SDK for windows or the PC Client CDRom included with ASE product. On the SDK its available as 12.5.1 and 15.0 On ASE PC Client I think 12.5.1 is part of ASE 12.5.X and 15.0 is part of ASE 15.X 2.0 provider should release som...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! Have a look into this links http://en.wikipedia.org/wiki/.NET_Framework http://blogs.msdn.com/mohammadakif/archive/2006/12/03/net-3-0-different-versions-of-the-net-framework.aspx http://www.codeproject.com/aspnet/ComparisonASP1xASP20.aspAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that m...

ado.net and .net 2.0
Does anyone know if there has been any notable changes to ADO.NET in .NET 2.0 in the areas of data access (both reads and writes) except for the new SqlDataSource and equivalent user controls? Try these links for  tutorials. Hope this helps.http://beta.asp.net/QUICKSTART/aspnet/doc/data/advanced.aspx#nulls http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql90/html/mandataaccess.aspKind regards,Gift Peddie...

Error with using .Net 3.0 instead of .Net 2.0
Hi,  I have recently made a website in microsoft visual web developer 2005.  When I have uploaded my site to my host I am having trouble.  when I visit the page www.amcnewzealand.co.nz I get an error message.  My web hosting company does not support .net 3.0 but instead use .net 2.0.  My website is made with file extensions .aspx.  I am usure how to tell what version of .net I am using and wether this is the only cause.  At first there was a 403 error occuring. Help would be much appreciated as I have been struggling with this for some time. The version...

Is exception raised in ADO.Net when a stored procedure has @@ERROR <> 0?
If, within a stored procedure in SQL Server 2000, an error occurs and therefore. the system variable @@ERROR  is not equal to 0, then will ADO.Net always raise an exception in its executing code? OR For ADO.Net to raise an error, the stored procedure must use : IF @@ERROR <> 0  RAISEERROR ('Stored Procedure error', 16, 1)  sun21170 In SQL Server 2000, the answer to this is Yes.  In SQL Server 2005, you can prevent this by using the BEGIN TRY, END TRY, BEGIN CATCH, END CATCH clauses.   Kind regards Scotty   Hi, No, ADO.NET will not al...

ADO.NET, GUID and ASA 8.0.2.4392 Stored Procedure...
Hello All, I am having issues... I have two tables The First is Category. Category Has Two Fields Category_ID type uniqueidentifier and Name type varchar(30) The second table is Value. It has three fields Value_ID type uniqueidentifier, Category_ID type uniqueidentifier and Name type varchar(30) I am connecting to the first table using ASADataReader with a simple select * from category. (there is only one record). I am filling a variable named _id type GUID with dr["Category_ID"]. The variable is populated and life to this point is good. Here is the st...

Migration from .net 1.1 to .net 2.0 and deployed in server: error "Server Application Unavilable"
Hi, I have upgraded one .net 1.1 application to .net 2.0. though locally the application is running fine, when deployed in the server it is giving the following error : Server Application Unavailable The web application you are attempting to access on this web server is currently unavailable.  Please hit the "Refresh" button in your web browser to retry your request. Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused thi...

Unable to debug .net 1.1 applications after installing .net framework 2.0 ? #2
Hi, After you install .NET Framework 2.0, if you continue to use Visual Studio.NET 2003 you may be unable to debug the applications developed in .NET 1.1. You may receive the error "Unable to start debugging on the webserver..." Please check My Article on this issue and the resolution for the same. Comments are welcome. Thanks. regards,Harishhttp://geekswithblogs.net/ranganh...

ADO.net dataset with 2 datatable store it into 1 stored procedure
Hi, i have 1 dataset which have 2 dataTable contain; dataTable 1: FieldName : firstname lastname jobtitle company mobiletelephone contact_Id Value: Barns Happy Executive Unigi 32123 0 dataTable2: Fieldname :address street city zipcode country telephone fax contact_Id 44Dover Dover Sg 12345 Singapore 2331 12313 0 I m trying to put the whole dataset into 1 stored procedure here's my code Public Function update(ByVal ds As DataSet) As B...

Application created in new version of .NET (3.0 or 3.5) can use the library created in older version of .NET(i.e.-1.0 or 2.0)?
Hi All, I am using Visual Studio .NET compiler for compiling my application . We have plugins (as library) which the user can write by their own in .NET . We are building our code in Visual Studio 2005 but we have already some plug-ins which are written in previous versions of Visual Studio (i.e. 2002 and 2003). Is these plug-ins will work with the new build of the application or I need to build these plug-ins as well in Visual Studio .NET 2005. These plugins are created as library. Is their any differences between .NET 1.0, 2.0 and 3.0 because of which the old libraries (created in o...

Clickonce deployment anyone (DW.NET 2.0 and .NET 2.0)?
I saw someone had posted a question about this already, and there were no responses. So I am hoping that this will get some. We had problems with the previous version of DW.NET 1.5 + VS2003 when attempting to deploy applications via a web server. So many problems that we eventually decided to run off a network drive (which is OK if your user base doesn't roam around the country). Anyway, we gave up on DW.NET, and started to use the datagrid control. Since then, much has changed. Our development team now has VS2005 professional and may start using DW.NET 2.0 (pending my inv...

.NET 3.0 or .NET 2.0?
I'm going to move my exiting software to .net soon. I'm just wondering if I should wait for the .NET 3.0 framework to be released or if I can start with the 2.0 now? I'd say you can go ahead and move your code to .Net 2.0 as .Net 3.0 uses the CLR version 2.0.Basically, .net 3.0 is .net 2.0 PLUS some new features for presentation (GUI), communication and workflow process.  So the compiler as well as the language features used by the 2.0 runtime will be the same in 2.0 and 3.0"Never argue with an idiot; He will drag you down to his level and beat you with experienc...

Web resources about - ADO.NET 2.0 - Three-tier application - connection string error - SQL store procedure - asp.net.presentation-controls

Application - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Perth man’s Afghan wife slapped with 10-year visa application ban - PerthNow Search Search
A MAN’S three-year struggle to have his wife live with him in Australia has ended in heartache after his spouse was slapped with a 10-year ban. ...

Development application for Holt golf course land open for public inspection
The developers selling 350 dwellings on disused parts of the Holt golf course have submitted their development application for public inspection. ...

Radius CEO Says Drug Application Delayed for `Work-Life Balance'
... Ward said. Radius fell 11 percent to $61.51 Tuesday after the company said in a statement that it was delaying submitting a new drug application ...

Samsung Unveils the Latest Application Processor, Exynos 8 Octa, Built on 14-Nanometer FinFET Process ...
Samsung Electronics Co., Ltd., a world leader in advanced semiconductor technology, today announced the newest member of its Exynos family of ...

MBA: Mortgage Applications Increase in Latest MBA Weekly Survey, Purchase Applications up 19% YoY
From the MBA: Mortgage Applications Increase in Latest MBA Weekly Survey Mortgage applications increased 6.2 percent from one week earlier, ...

Elon Musk Requests Applications For Autopilot Software Engineers On Twitter
... and more quickly achieve “generalized full autonomy.” So, if you ever wanted to work for Tesla in such a [&hellip Elon Musk Requests Applications ...

Mortgage applications rise 6.2%
Home loan borrowers seem undeterred by the highest interest rates in five months.

Help wanted: Obama's tech-training project now accepting applications
Organizers of innovative training programs can now apply for a federal grant to help prepare low-wage workers for more-lucrative tech jobs.

Thousands of Java applications vulnerable to nine-month-old exploit
A popular Java library has a serious vulnerability, discovered over nine months ago, that continues to put thousands of Java applications and ...

Resources last updated: 11/24/2015 12:54:28 PM