.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

Does C# "anticipate" failed SQL statements and prevent code from being executed?

Posted By:      Posted Date: October 18, 2010    Points: 0   Category :ASP.Net

Hi Smile

I'm allowing a user to attach a piece of information to a table.  Before the INSERT statement, I put a check in to see if the table already contains that piece of information, and if so, give an alert dialog box to say, "oops, this is already in the table, no action taken."

To do this check, I'm simply using COUNT with the WHERE clause on the table to see if the data attempting to be entered is already there.  I then set a boolean flag to true or false.  True if the data is already there, and false if it is not.

This is the general idea of the code, with the SQL statements/parameters/etc. abbreviated:

    protected void InsertPCButton_Click(object sender, EventArgs e)
        Boolean alreadyattached = false;

        using (SqlConnection myconn = new SqlConnection(sqlconnstring))
            //SQL command/statements to get the count on the table

            if (count != 0)
                alreadyattached = true;

        if (alreadyattached == true)
            Response.Write("<script>alert('This PC is already attached to this case.  No action taken.')</scrip

View Complete Post

More Related Resource Links

Debug Leaky Apps: Identify And Prevent Memory Leaks In Managed Code


When is the .NET Garbage Collector unable to reclaim memory? The answer might surprise you. Stay tuned.

James Kovacs

MSDN Magazine January 2007

Custom tool error: Failed to generate code for the service reference 'CompanyService'. Please che


A little background because I feel I have an out of the ordinary architecture in place and don't know if this is contributing to the problem. 

We have an existing ASP.net application that is undergoing expansion.  The new functionality is all written in Silverlight 4.  As part of that expansion I gutted all the old Linq to SQL and put Entity Framework 4 into place.  To do this I created a standard .net Class Library and added my edmx files there.  Naturally, the business entities created by this cannot be used in Silverlight.  So I created a Silverlight Class Library and added all the business entities to that Silverlight Class Library as linked files.  I changed the name space to be the same.

So I have the following assembly / namespaces

Company.Project.Dal.csproj / Company.Project.Entities (.net 4 class library)

Company.Project.Entities.csproj / Company.Project.Entities (SL4 class library)

With this architecture I was able to share my business entities with my SL enabled web services, my asp.net projects, my silverlight projects.  Really it's a beautiful thing.

Once this was done I added "message" classes to Company.Project.Dal and again shared them with the other entites using linked files.  These messages are things like MyObjectRequest; they are class

Failed to initialize MSDB database for tuning (exit code: -1073741819). (DTAClient)

Hello,This is the first time I am using this forum. I am stuck and need some help. I received this error message both on SQL 2005 and 2008. I am currently using SQL 2008 DEV for testing purposes and I am experiencing this error message when trying to connect to Database Engine Tuning Advisor. I am using the SA account so I should not have any security issues. Also this is a fresh install of SQL 2008 DEV on a fresh install of Windows XP Pro with all SP. Can some please help.Error:"Failed to initialize MSDB database for tuning (exit code: -1073741819). (DTAClient)"=================================== Failed to open a new connection. =================================== Failed to initialize MSDB database for tuning (exit code: -1073741819). (DTAClient) ------------------------------Program Location:    at Microsoft.SqlServer.Management.DTA.Client.TuningServer.InitializeTuningParametersDatabase()   at Microsoft.SqlServer.Management.DTA.Client.TuningServer.InitializeConnection()   at Microsoft.SqlServer.Management.DTA.Client.TuningServer.Connect()   at Microsoft.SqlServer.Management.DTA.Shell.SessionMonitor.AddServerInternal(SqlConnectionInfo connectionInfo, SqlConnection connection)   at Microsoft.SqlServer.Management.DTA.Shell.SessionMonitor.AddServer(SqlConnectionInfo connectionInfo, SqlConnection connection)   at Microsoft.SqlServer.Management.DTA.Shell.SessionMonitor.On

ocienvcreate failed with return code -1

Hi. Its problem is generated in a Windows 2000 server and vb.net application. The users connect to aplication by terminal server. This is a permission problem... Thanks....DFPP

hotfix 3024 error code 1603 - failed install

Hello experts - Installing sql server 2005 on a 2 node cluster and failed with the above error.  I see lots of posts regarding this error, but no answers.  A search of the registry reveals no 3024 entries. Any help appreciated - DianneDianne

Server failed with error code 0xc0000000 to spawn a thread to process a new login or connection

Hello All, Suddenly, the sql server is down, in the log file, C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG, I found the record as follows, 2007-03-05 15:40:31.59 Logon       Error: 17189, Severity: 16, State: 1.2007-03-05 15:40:31.59 Logon       SQL Server failed with error code 0xc0000000 to spawn a thread to process a new login or connection. Check the SQL Server error log and the Windows event logs for information about possible related problems. [CLIENT:] What else I can do to further investigate? Thanks Spencer

SQL Express 2008 Installation failed. Process exited with code -2067529712

Property: [AdminUser] = true {boolean}Property: [ProcessorArchitecture] = AMD64 {string}Property: [VersionNT] = 6.0.1 {version}Running checks for package 'Microsoft Data Access Components 2.8', phase BuildListReading value 'FullInstallVer' of registry key 'HKLM\Software\Microsoft\DataAccess'Read string value '6.0.6001.18000'Setting value '6.0.6001.18000 {string}' for property 'MDACVersion'The following properties have been set for package 'Microsoft Data Access Components 2.8':Property: [MDACVersion] = 6.0.6001.18000 {string}Running checks for command 'MDAC28\mdac_typ.exe'Result of running operator 'VersionGreaterThanOrEqualTo' on property 'MDACVersion' and value '2.80': trueResult of checks for command 'MDAC28\mdac_typ.exe' is 'Bypass''Microsoft Data Access Components 2.8' RunCheck result: No Install NeededRunning checks for package '.NET Framework 2.0 (x86)', phase BuildListRunning external check with command 'C:\Users\barneyfife\AppData\Local\Temp\VSDC947.tmp\DotNetFX\dotnetchk.exe' and parameters ''Process exited with code 1Setting value '1 {int}' for property 'DotNetInstalled'Reading value 'Version' of registry key 'HKLM\Software\Microsoft\Internet Explorer'Read string value '8.0.6001.18783'Setting value '8.0.6001.18783 {string}' for property 'IEVersion'The following properties have been set for package '.NET Framework 2.0 (

Cannot see output from Print statements executed within SQL Server Management Studio

When I execute a Print statement in a query within Management Studio, I get no output in the Results Pane (Messages tab).  I've worked with Oracle mostly and there I had to enable dbms output in the database session AND enable output within the tool I was using (Quest SQL Navigator) before any output could be seen.  Is there something similar that I need to do when working with SQL Server and SQL Server Management Studio? FYI, I DO get output if I use RAISERROR('yadda',16,1), but nothing if I use Print 'yadda'. I appologize if there's an answer to this already in the forums, but I searched and couldn't find it. Thanks, Neil

.NET Framework 4.0 -- Installation failed with error code: (0x80070658), "Error applying transforms.

I’m getting the following error when installing .NET 4.0.   Final Result: Installation failed with error code: (0x80070658), "Error applying transforms. Verify that the specified transform paths are valid"   These are the steps I took to try and solve the problem but no luck:   1.       Uninstalled all versions of .NET 2.       Ran the .NET Cleanup Tool 3.       Installed .NET 4.0 but it failed   Any ideas?   Here is the last part of the log file with error at the bottom:   [9/7/2010, 14:41:57]calling PerformAction on an installing performer [9/7/2010, 14:41:57] Action: Performing actions on all Items... [9/7/2010, 14:41:57]Wait for Item (RGB9RAST_x86.msi) to be available [9/7/2010, 14:42:0]RGB9RAST_x86.msi is now available to install [9/7/2010, 14:42:0]Creating new Performer for MSI item [9/7/2010, 14:42:0] Action: Performing Action on MSI at C:\DOCUME~1\adelgadi\LOCALS~1\Temp\Microsoft .NET Framework 4 Setup_4.0.30319\RGB9RAST_x86.msi... [9/7/2010, 14:42:0]Log File C:\DOCUME~1\adelgadi\LOCALS~1\Temp\Microsoft .NET Framework 4 Setup_20100907_144152567-MSI_RGB9RAST_x86.msi.txt does not yet exist but may do at Watson upload time [9/7/2010, 14:42:0]Calling MsiInstallProduct(C:\DOCUME~1\adelgadi\LOCALS~1\Temp\Microsoft .NET Framework 4 Setup_4.0.3

.NET Framework 4.0 Full package installation failed with error code: (0x80070643)

I am getting an error when installing .net framework 4.0. I am using the full package installer. OS: windows XP Service Pack 3 Windows Update: Current with all security updates. Error: [7/12/2010, 10:50:49]MSI (C:\eb1ddbb12a129b2fddde4054\netfx_Core_x86.msi) Installation failed. Msi Log: Microsoft .NET Framework 4 Setup_20100712_105014316-MSI_netfx_Core_x86.msi.txt [7/12/2010, 10:50:49]PerformOperation returned 1603 (translates to HRESULT = 0x80070643) [7/12/2010, 10:50:49] Action complete [7/12/2010, 10:50:49]OnFailureBehavior for this item is to Rollback. [7/12/2010, 10:50:49] Action: Performing actions on all Items... [7/12/2010, 10:50:49] Action complete [7/12/2010, 10:50:49] Action complete [7/12/2010, 10:50:57]C:\eb1ddbb12a129b2fddde4054\netfx_Extended.mzz - Signature verified successfully for netfx_Extended.mzz [7/12/2010, 10:50:57] C:\eb1ddbb12a129b2fddde4054\netfx_Extended.mzz Signature verified successfully for netfx_Extended.mzz [7/12/2010, 10:50:57]Signature verification succeeded for netfx_Extended.mzz [7/12/2010, 10:50:57]File C:\eb1ddbb12a129b2fddde4054\netfx_Extended.mzz, locked for install. [7/12/2010, 10:50:57]Verifying Digital Signatures: C:\eb1ddbb12a129b2fddde4054\netfx_Extended.mzz Success [7/12/2010, 10:50:57]Final Result: Installation failed with error code: (0x80070643), "Fatal error during installation. " (Elapsed time: 0 00:00

.NET 3.5 SP1 failed with the error message - Error code 1603 for this component means Fatal error du

I had Beta version of VS 2008 and I wanted to install .NET 3.5 SP1. Installation led to some serious problems. I tried almost everything to install .NET 3.5SP1 (or VS 2008 SP1), nothing works

* VS 2008 has been uninstalled
* 3.5 uninstalled and cleaned
* 3.0 uninstalled and cleaned
* WF components removed
* document manager components removed

when I try to reinstall 3.5SP1, I keep receiving the following error in dd_dotnetfx35error

[01/11/09,00:23:05] XPSEPSC Installer: [2] Error code 1603 for this component means "Fatal error during installation.
[01/11/09,00:23:06] XPSEPSC Installer: [2] Setup Failed on component XPSEPSC Installer
[01/11/09,00:23:32] WapUI: [2] DepCheck indicates XPSEPSC Installer is not installed.

Then I check the contents of dd_dotnetfx35install for the event error log and found the following
[01/11/09,00:23:05] XPSEPSC Installer: ***ERRORLOG EVENT*** : Error code 1603 for this component means "Fatal error during installation.
[01/11/09,00:23:05] Setup.exe: AddGlobalCustomProperty
[01/11/09,00:23:06] XPSEPSC Installer: ***ERRORLOG EVENT*** : Setup Failed on component XPSEPSC Installer
[01/11/09,00:23:06] Setup.exe: GetGlobalCustomProperty - Property: {BBE1827C-F2FD-4FDA-A6D6-C83B62FFFDCA} - PropertyName: compfailed - Value: 0
[01/11/09,00:23:06] XPSEPSC Installer: CBa

.NET Framework 4 Final Result: Installation failed with error code: (0x80070643)


While trying to install Microsoft Visual Studio 2010 i got some errors on .NET framework 4.0, so i tried the standalone .NET 4 installer from microsoft and i got these errors.

MSI (H:\8c4b5e7f61c15fc5cf9e70de2e\netfx_Extended_x86.msi) Installation failed. Msi Log: Microsoft .NET Framework 4 Setup_20100924_134502282-MSI_netfx_Extended_x86.msi.txt
[9/24/2010, 13:51:7]PerformOperation returned 1603 (translates to HRESULT = 0x80070643)

[9/24/2010, 13:51:7] Action complete

[9/24/2010, 13:51:7]OnFailureBehavior for this item is to Rollback.

[9/24/2010, 13:51:7] Action complete

[9/24/2010, 13:51:7]Final Result: Installation failed with error code: (0x80070643), "Fatal error during installation." (Elapsed time: 0 00:06:05).

SQL Express 2008 R2 failed to install: Exit error code: 17115


I'm trying to install SQL Server Express 2008 R2, but I keep getting errors.  I've probably tried 10 to 15 times over the last weeks, always trying something different.  Yes, I'm learning to read the logs, the summary.txt provided below.  The last two times I've noticed that the exit code, exit facility code, and error code are the same in this log.  I tried following one post that had these codes and had long/detailed procedure on how to remove SQL manually, especially traces from the registry.  It didn't solve my problem.  I get no errors on removal, everything removes successfully.  So what to do?  Thanks for your help.  --Ralph

Overall summary:
  Final result:                  SQL Server installation failed. To continue, investigate the reason for the failure, correct the problem, uninstall SQL Server, and then rerun SQL Server Setup.
  Exit code (Decimal):           -1035451685
  Exit facility code:            584
  Exit error code:               17115
  Exit message:      &nbs

SQL Server installation failed Exit code (Decimal): -2068643839 Exit facility code: 1203


I am installing the MS SQL SERVER 2008 enterprise edition on Windows XP. I created different accounts to start different services. I also created an account SQL_ADMIN to be used at the admin account. However to this user I did not give administrator priv on windows. Is it needed? I get the following error. Please help.


Overall summary:
  Final result:                  SQL Server installation failed. To continue, investigate the reason for the failure, correct the problem, uninstall SQL Server, and then rerun SQL Server Setup.
  Exit code (Decimal):           -2068643839
  Exit facility code:            1203
  Exit error code:               1
  Exit message:                  SQL Server installation failed. To continue, investigate the reason for the failure, correct the problem, uninstall SQL Server, and then rerun SQL Server Setup.
  Start time:                  &nb

SSPI handshake failed with error code 0x80090311



Yesterday, all of a sudden, I received 15 alerts from my sql2k8 R2 64bit with the same content as follows:

DATE/TIME:       9/27/2010 8:54:01 PM


DESCRIPTION:   SSPI handshake failed with error code 0x80090311, state 14 while establishing a connection with integrated security; the connection has been closed. Reason: AcceptSecurityContext failed. The Windows error code indicates the cause of failure.  [CLIENT: <named pipe>].

How can this be troubleshooted. I can access my sql withoiut any problem through sharepoint or SSMS.

How does web part stores its properties when a piece of code is executed in it?



I am trying to program my first webpart based on this:


This webpart must show people who have birthdays on particular day of the month. There should be a button for each month (and one for "whole year) and button for each day (and one for "whole month") and so user can choose to show only those with birthdays in say, april 23, or whole june...

I did it this way:

Following the tutorial, i create all my controls inside the CreateChildControls() and i store references to them as properties of the webpart class. Also the class (public class BirthdayFullScreenWebPart) has properties (int chosen_month) and (int chosen_day).

Then i have have onclick for buttons that changes the chosen month and/or day web part property, based on which button was clicked.

Then i have a function "UpdateUserList" that ouptuts list of users into the webpart's table control, based on the chosen month and day. this function is called inside createchidlcontrols after all of them are created, and inside onclicks when the month/day is changed.


What i got is that the values of the variables were behaving really odd. 

In my mind, it

Sql Server Agent failed to executed a scheduled bat file that contains sqlcmd command


Hi All:

I am currently using Windows 2003 R2, Standard Edition.
I have Microsoft Sql Server 2005 Installed with the latest service pack which is sp3.
I logged into the operating system as an administrator. The windows administrator id is "test2".
I logged into the Microsoft Sql Server 2005 database using "Microsoft Sql Server Management Studio" as an "sa" which is database admin.
I placed a bat file called "test1.bat" in the directory c:\test3, the file "test1.bat" contains the following content:


In the dos-prompt, I can run the "test1.bat" batch file with no errors.
It gives me the following output:

Using "Sql Server Agent", I created a new job called "Scripts1".
For the "General" link, I have the following values:
Category:Database Maintenance

For the step link, I have the following values:
Step Name:test2
Type:Operating system(CmdExec)
Run As:SQL Agent Service Account

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