.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Database deletion not working when parameter involved

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :ASP.Net
Hi,I have a system in which users can enter records into a database via ajax.  Each user may hold many values in the database, with different pageId and itemId values.  Each user is identified by a GUID set to a cookie.  The system needs to prevent the user from entering two pieces of data with the same pageId and itemId, so I've created a script to do two database updates:Firstly, all records are deleted from the database where the memberGUID, pageId and itemId fields match (i.e. they've already added this item).Secondly, the record is then recreated.It all works brilliantly, except when the GUID value is passed into the delete statement, then I just get a caught exception.So this works: public class UpdateValue { public static string Hello(int pageId, int itemId, string inOut, string period, decimal value) { //Initialise variables and objects string cookie = HttpContext.Current.Request.Cookies["visitorGUID"].Value; inOut = inOut.Substring(0, 1); //Delete value if already present SqlConnection connDel; connDel = new SqlConnection(GlobalSettings.DbDSN); SqlCommand commDel; commDel = new SqlCommand("DELETE FROM budgetData WHERE pageId = @pageId AND itemId = @itemId;", connDel); commDel.Parameters.Add("@pageId", System.Data.SqlDbType.Int); commDel.Parameters["@pageId"].Value = pag

View Complete Post

More Related Resource Links

Logging to database is not working



Am using Enterprise library 4.0 for logging exceptions to SQL server database. The code is working fine if I run my asp.net application from the Visual studio IDE.However if I publish the site and host it on IIS, then my application is not logging the errors to database.Here is the page load event of my application.Kindly help me in finding out the error.

Thanks in advance


 protected void Page_Load(object sender, EventArgs e)
                //If exception occurs due to unauthorized access
                if ((Request.QueryString["Unauthorized"] != null) && (Request.QueryString["Unauthorized"].Equals("Y")))
                        lblErrorMessage.Text = "You are not authorized to view this page";
                        //Get the user and machine names                       
                        string strUserName = User.Identity.Name;
                        string strMachineName = System.Environment.MachineName;
                        //Raise Error
                        throw new System.UnauthorizedAccessException("Unauthorized access--User Name:" + strUserName + "--Machine Name:" + 

SQL Server Force Parameter at the database level?

If you do opt for force parameter at the database level, as I read SQL Server rebuilds plan cache but my questions is does that mean it rebuilds data cache also? Any things to watch out and your experiences dealing with force parameter at the db level..

restore SQL server 2005 database on new SQL server 2008 not working

please any one advice me ,i have Great Plain database on SQL server 2005 when i tried to install new SQL server 2008 and restore my Database the GreatPlain not working well as well the Data Base

passing parameter from one report to another (SSAS database)?


 I created two reports using SSAS Databse as the report datasource.I need to call one report from another report while clicking one of the textbox(text Box properties--> action --> Hyperlink GO to Report)

1) How should I pass the parameter from one report to another (bcos I should pass like this [Month].[Month Name]&[09] ) ?
2) How Should I pass the parameter if I am using hyperlink "go to URL" to call the report?


url with parameter working on local but not on server


hi, I am working in asp.net MVC....

Not sure if this is a bug, or a misconfiguration on my part, but the &output= doesn't work on the IIS7 server but it works fine on local VS Web server(2008) i.e.

 http://localhost:12345///&format=xml works,

but http://www.example.com///&format=xml doesn't.

please let me know what can be the problem & how can i resolve that


thanks in advance


reportviewer date parameter and calendar.. not working and javascript errors??



Hi, I've got this ssrs 2005 report that works great passing a few
security related parameters from asp.net codebehind. However, there
are two date related parameters that won't be coming from my web form,
but rather from the report form itself. When I test the report's date
parameters from visual studio it work fine, but when I attempt the
same report from a reportviewer no matter what input I place on the
report's date fields or even if I select the date picker, the report
simply resets to default and reloads. And actually the date picker
from the reportviewer does not not even pop up.


Here's my aspx code:

<%@ Page Language="VB" AutoEventWireup="false"
Inherits="_ReportViewer" MasterPageFile="~/Main/MasterPage.master"
    CodeFile="~/Reports/CashSales.aspx.vb"  Title="Cash Sales" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms,
Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Content1"

Database.Open("wishlist"); in MVC3 controller not working


I am unable to reference the WebMatrix.Data dll with this using statement in my controller:

using WebMatrix.Data;

Therefore I can't use this statement:


Anythought on how to add the dll to my project?  I can't seem to find it in the Programs/Webmatrix folder.




Master Data Deletion in Large Database Applications


I am working on School MIS application and apparently, it has many Master profiles, like School, Student, Class, Division, Employee etc. In order to keep my database integrated and to maintain the consistency of data whenever someone deletes a master data then everything related to that data also gets deleted.

However, as the application is progressing I am wondering if it is a right way to do it because when someone deletes a master data then there is hell lot of data which would also get deleted. And the related data which would get deleted would in turn have other related data.

So if in my application if someone would delete a school then all the information related with a school like Students, Classes, Sections, Division, Employees should also get deleted and Students in turn would be associated with other data which should also get deleted.

I was wondering what would be the best approach? What if someone deletes a master record it by mistake, though we would take the confirmation before deleting but if by any chance someone does it by mistake then it would cost the organizationa lot:)

1) Should we really provide a feature to delete a data or when user tried to delete a data then maybe we can deactivate it and all other related data by setting some flag in the table.

2) If we have to delete the data then, should we just take confirmat

How To check Database Connection working or not in SSIS?


Hi All,


Before execute the package I want check db connection properly working or not. If don’t have proper connections I want display custom message. How to implement this task in ssis





database parameter specified with the configdb command is invalid error


Im using:

Windows server 2008 32 bit. SQL Server 2008 Enterprise. Sharepoint server 2007 Sp2.

I am trying to runthe fllowing command but getting the error that follows:

Psconfig -cmd configdb create -server "sername" database DBName user Domain\user password pswd admincontentdatabase SharePoint_AdminContent

The database parameter specified with the configdb command is invalid.
The database name located at the specified database server has an incorrect coll
ation.  Rebuild the database with the Latin1_General_CI_AS_KS_WS collation or cr
eate a new database using the Latin1_General_CI_AS_KS_WS collation.

Can anyone tell me how to sort this out?


Odd database name generated after CDatabase::OpenEx is called when AttachDBFilename parameter is too


Using the following code to attach a mdf file to my sql server database, notice the AttachDBFilename is longer than 128

CString strConn;
 strConn = "DRIVER=SQL Server;SERVER=XXXX;AttachDBFilename=E:\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\db2.mdf;UID=xxxx;PWD=xxxx";
 CDatabase da;
 DWORD dwOptions = CDatabase::noOdbcDialog;
 BOOL bReturn = da.OpenEx(strConn, dwOptions);
 MessageBox( _T("true") );

the above code can work successfully, but after I find the database in SQL server management studio, the database name is as following:


You can see the created name is different from its original file path because the full path for mdf file is too long. My question is how can i get the above odd database name in my code?

Bulk Insert into Access Database not working for template fields in gridview



I have a gridview with 5 columns

4 are fetched from database through select command from table CSDB_MASTER

5th is a template field textbox which consists of value 3 by default

now i have a button down to the gridview with the following code below

everything is being inserted except the value of textbox, when i open my database the field NOC which should be inserted with grv.cells[5].Text i.e, the textbox value is null

Please Help Me Out in this issue


protected void Button1_Click(object sender, EventArgs e)

        OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\masterdb.accdb;Persist Security Info=False;");
        OleDbCommand cmd = new OleDbCommand();
        cmd.Connection = con;

        foreach (GridViewRow gvr in GridView1.Rows)

Bulk insert into access database not working with template fields in gridview


how to insert data into access database from gridview containing template fields

Linked Server for MySQL database not working


Dear All,

I have installed MySQL Database on my local PC (WAMPServer 2.1)
I want to update few tables in my SQL Server (2008) Database from MySQL Database.

To achive this I have created a linked server in SQL Server for MySQL Database using System DSN. Now I can query to all tables from linked server for example:


It reterive few rows and then give error message

Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
Msg 0, Level 20, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.


Passing a parameter to XSLT, then to XmlDataSource is not working


I'm stumped. I'm trying to get this to work, but nothing is happening. Basically what I want is when I click the header links the xml in the gridview will ort by whatever column.

Here's the code:

<?xml version="1.0" encoding="utf-8" ?>
    <data name="Test1.Text" xml:space="preserve">
        <value>Please Pick Bare Pump</value>
        <comment>Tab - Pump Configuration</comment>
    <data name="Test2.Text" xml:space="preserve">
    <data name="Test3.Text" xml:space="preserve">

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

    <xsl:param name="sortby"></xsl:param>
    <xsl:output method="xml" indent="yes"/>
    <!--<xsl:template match="@* | node()">
            <xsl:apply-templates select="@* | node()"/>
    <xsl:template match="root">

How to get output parameter asp.net 3.5 database is mysql 5.1



I am using mysql 5.1. odbc driver 5.1.

I have created a stored proc and declared a parameter as output. In asp.net I am getting an error.

ERROR [HY000] [MySQL][ODBC 5.1 Driver][mysqld-5.5.11]OUT or INOUT argument 7 for routine facebookdb.SP_FB_Add_Registration is not a variable or NEW pseudo-variable in BEFORE trigger

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.Odbc.OdbcException: ERROR [HY000] [MySQL][ODBC 5.1 Driver][mysqld-5.5.11]OUT or INOUT argument 7 for routine facebookdb.SP_FB_Add_Registration is not a variable or NEW pseudo-variable in BEFORE trigger

please help me out how to get the value of output parameter

Multiple database support with Entity Framework

One of the features introduced in Entity Framework is being database independent. Which mean each database provider can support Entity Framework by implementing its provider.

This feature allows you build applications independent from the underplaying database provider. In this post I'm going to show how to build an application that support multiple databases using same conceptual model made by Entity Framework.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend