How to display SQL Server Error Message on Web Form

I have following Stored Procedure ... How do I display Error Message Return by Stored Procedure ??

CREATE PROCEDURE [AddNewUserDetails]
(
@UserName nvarchar(30),
@Passcode nvarchar(10),
@FName nvarchar(30),
@LName nvarchar(30),
@UserRoleID int,
@AccStatus nvarchar(50)
) AS
IF EXISTS ( SELECT 'TRUE' FROM UserDetails where logname = @UserName)
BEGIN
-- Notify user about duplicate username
SELECT 'Username already exists'
END
ELSE
BEGIN
-- Username doesn't exists in database, add it and notify admin
SELECT 'Record Added'
DECLARE @userid int
SELECT @userid = MAX(userid) + 1 FROM UserDetails
INSERT INTO UserDetails VALUES (@userid, @UserName, @Passcode, @FName, @LName, @UserRoleID, @AccStatus)
END
GO

Here is the code for Calling Stored Procedure
public string AddNewUserDetails(string UserName, string Passcode, string FName, string LName, int UserRoleID, string AccStatus)
{
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand myCommand = new SqlCommand("AddNewUserDetails", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterUserName = new SqlParameter("@UserName", SqlDbType.NVarChar, 50);
parameterUserName.Value = UserName;
myCommand.Parameters.Add(parameterUserName);
SqlParameter parameterPasscode = new SqlParameter("@Passcode", SqlDbType.NVarChar, 50);
parameterPasscode.Value = Passcode;
myCommand.Parameters.Add(parameterPasscode);
SqlParameter parameterFName = new SqlParameter("@FName", SqlDbType.NVarChar, 50);
parameterFName.Value = FName;
myCommand.Parameters.Add(parameterFName);
SqlParameter parameterLName = new SqlParameter("@LName", SqlDbType.NVarChar, 50);
parameterLName.Value = LName;
myCommand.Parameters.Add(parameterLName);
SqlParameter parameterUserRoleID = new SqlParameter("@UserRoleID", SqlDbType.SmallInt, 2);
parameterUserRoleID.Value = UserRoleID;
myCommand.Parameters.Add(parameterUserRoleID);
SqlParameter parameterAccStatus = new SqlParameter("@AccStatus", SqlDbType.NVarChar, 50);
parameterAccStatus.Value = AccStatus;
myCommand.Parameters.Add(parameterAccStatus);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (SqlException ex)
{
Console.WriteLine(ex.Message.ToString());
return ("Error Adding New User Details");
}
finally
{
myConnection.Close();
}
return ("New User Added Successfully");
}
0
love_luv
4/13/2004 5:21:11 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

0 Replies
838 Views

Similar Articles

[PageSpeed] 21

Reply:

Similar Artilces:

Error message about SQL Server is displayed
I have a website that works OK on my local machine when I test it within Microsoft Visual Studio's debugging mode. However now that I have copied it over to a remote server it is failing with an error message of: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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)As far as I'm aware I have never used SQL Server with ...

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
Hi All, i am using tha conncetion string in web.config. <add name="MyLocalSqlConnection" connectionString="Data Source=.\SqlExpress;AttachDbFilename=|DataDirectory|\SqlServer\OC00003SQL.mdf;User Instance=false" providerName="System.Data.SqlClient"/>  Instance=false and true both i have used  but i am getting error like that. on my web hosting site  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 Serv...

connecting to SQL 2000 Server gives SQL 2005 error message
Hi, Here is the syntax of the connection string within the web.config file:<connectionStrings><clear /> <add name="MyConnectionString" connectionString="Data Source=000.000.000;Initial Catalog=Database Name;Persist Security Info=True;User ID=XXXXXX;Password=XXXXXX;" providerName="System.Data.SqlClient" /> </connectionStrings>  The test page has a GridView in it which uses the connectionstring fron the web.config file. Error Message: An error has occurred while establishing a connection to the server.  When connecti...

SQL Server 2005 Error, but its SQL Server 2003?
Here is an error we are getting when trying to connect through our websites: .Net SqlClient Data Provider 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)   The server is actually SQL Server 2003.  Windows Update installed a few updates yesterday, so we're thinking that something in the update might be causing this er...

SQl Server Error: ----> Named Pipes Provider, error: 40
  Hi Friends, Im using .Net2008 and MS SQL Server2005, I Have a web application , i want to connect to the server machine SQL Server,  When i run the application im getting the following error. Im trying to connect to the database from local machine application to server machine database   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 - Cou...

Is a SQL Server Device CAL enough if SQL Server is being accessed by only one web server?
 In my application scenario, there is a single web server hosting my ASP.Net application. If I buy a 'single device CAL'  for SQL Server database, will that be ok in this situation since only one device (i.e. the machine hosting the IIS web server) is going to access the SQL Server database?sun21170 No, that won't be enough.http://www.microsoft.com/sql/howtobuy/sqlserverlicensing.mspx  -- "Mark As Answer" if my reply helped you --...

SQL Server Reporting Services for SQL SERVER 2000 AND Visual Studio.NET 2005 .NET 2.0
Hi, Which version of SQl Server Reporting Services will work with SQL SERVER 2000 in pararrel with ASP.NET 2.0 (.NET 2.0 framework)?  Thanks, Azam HighOnCodingWanna get high! Hi, Okay I got the answer. Yes, we can use the SQL SERVER 2005 Reporting Services with SQL SERVER 2000. HighOnCodingWanna get high! ...

Displaying Image from SQL Server on Mobile Web Form
Hi,I'm new to mobile web development and need some kick start on  "Displaying Image from SQL Server on Mobile Web Form".... Please help me out. Thanks    Hi, I have code which retrieves the images from sql server and displays it on the mobile web form. Hope this helps.   byte[] data = new byte[0];  SqlConnection conn = null;       string doxtopDbConn = ConfigurationManager.AppSettings["doxtopDbConn"];             try   &nb...

Why does a simple select query in Microsoft Access return the error [Intersolv][ODBC SQL Server Driver][SQL Server]ct_results(): user api layer: internal client library error: Read from the server has
I have applied the information from support document 10447954 but that does not solve the problem. I am running a simple select query with one criteria from one table. Thanks. ...

Why does a simple select query in MS Access return the error: [Intersolv][ODBC SQL Server Driver][SQL Server]ct_results(): user api layer: internal client library error: Read from the server has timed
I have applied the information contained in support document 10447954. That did not resolve the problem. I am running a simple query with one criteria and one table Thanks. Hi Bill, The doc refers to a different ODBC driver (for DirectConnect product) so you might have a completely different problem. The message implies you are using ODBC 12.0 (Client Library based) or prior since the message indicates CtLib info. You might want to post more details involved with getting to this error. You also might want to post exact versions of ASE and ODBC driver, including Open ...

Problem with SQL Server connection string - provider: SQL Network Interfaces, error: 26
Hi Guys, I am having a wierd problem. The system works perfectly when I am connected to the local network but throws the above error when I disconnect it from the network. Given below are my connectionstrings: integrated security=false;user id=U1;data source=localhost;persist security info=False;password=pwd1;initial catalog=MyDB //connection string to my database Data Source=localhost;Initial Catalog=aspnetdb;User ID=U2;Password=pwd2 //connectionstring to aspnetdb for webparts I have also changed all the providers (SQLMembership, SQLProfile, SQLRole) to use LocalSQLServer and comme...

Displaying MS SQL Server 7.0 Error Messages
When migrating my database from SQL Anywhere 5.0 ODBC to MS SQL Server 7.0 ODBC, my PB code no longer displays database errors correctly: messagebox("Update Error", "An error occured while loading " + as_error + " table. All records may not have saved.~n~n" & + "SqlCode: " + string(sqlca.sqlcode) + "~n~n" + "SqlErrText: " + string(sqlca.sqlerrtext) ) Always displays SqlCode of 0 and blank SqlErrText. What is the proper way display the SQL Server 7.0 database errors? Thanks, Dale I was really hoping to ...

Connecting to sql server 2000 on Godaddy error: (provider: Named Pipes Provider, error: 40
Facts:1. I am using my account on Godaddy trying to connect to my sql server db.2. I can get into my db using user id and password.3. Godaddy's help file shows this for a connection string: connectstr = "Driver={SQL Server};SERVER=" & db_server & ";DATABASE=" &db_name & ";UID=" & db_username & ";PWD=" & db_userpassword4. My connection string: "Server=whsql-v09.prod.mesa1.secureserver.net;uid=dbasolutions;pwd=***;database=DB_87972;"  & _                    "Trusted_Connecti...

SQL Server 2005 tools with SQL Server 2000 error
Has anyone run into this error below yet?  I had a SQL Server 200 Database and then I installed the new SQL Server 2005 tools to use for development and now when I load the database over to my production server that has SQL Server 2000  I get this error... (I never got this error before I installed the tools but I know other people that use the tools with SQL Server 2000 and have no problems at all) Server Error in '/ParkingViolations' Application. An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this fai...

Web resources about - How to display SQL Server Error Message on Web Form - asp.net.sql-datasource

Samples of display typefaces - 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 ...

Paris attacks: France holds solemn ceremony for victims of terror attacks, displays pictures of 130 killed ...
President Francois Hollande tells a memorial for victims of the Paris Attacks that France will respond to the army of fanatics with songs, concerts ...

Flagship Oppo r7s with 5.5-inch display launching December 1, pre-order now in Europe
Chinese smartphone manufacturers are known for making great devices at affordable prices. While it may not be as popular as the likes of Xiaomi ...

Quantum Dot vs OLED, which is the better display?
... sums of money into new production lines and market researchers are predicting a huge growth in revenue over the next few years. OLED displays ...

Lava Iris X10 Listed Online, HD Display & 3GB Of RAM In Tow
Lava is one of the largest India-based smartphone manufacturers. This company tends to release quite a few devices on a yearly basis, and 2015 ...

Appleā€™s iPhones to feature OLED displays from 2018
It looks like Apple is set to bring an OLED display to its line of iPhones starting in 2018, according to a recent report. The news comes from ...

Too Early To Say If iPhones Will Use Universal Display, But Stock Still A Buy: Gabelli
Universal Display ( OLED ) has been gaining ground recently on rumors that Apple ( AAPL ) may adopt its displays for its 2018 version of the ...

Amazing infographic shows how many Nokia 5110 displays fit in an iPhone
... game Snake, will know that modern smartphones have come quite a way since then. But on a pixel by pixel basis, how much better is the display ...

Digitimes Research: Korea makers to mass produce transparent OLED displays in 2016
Korea panel makers have plans to mass produce 55-inch and above size transparent OLED displays from 2016 into 2017, according to Digitimes Research. ...

Tech-y Shoes Sport Flexible, Customizable Display
These kicks have flexible displays so you can change their design on the fly from your phone.

Resources last updated: 12/3/2015 7:21:59 AM