473,513 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dataAdapter.Update / SQL PasswordHash NULL problem

93 New Member
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously stated. Also please note that this is unrelated to another of my previous threads, “dataAdapter.Update problem”, which incidentally has been resolved.

I’m learning SQL. I’m accessing database SQL2008 AdventureWorks, table Person.Contact, which has a column PasswordHash, of type varchar (128). Here’s the code I’m using to save records:
Expand|Select|Wrap|Line Numbers
  1. // here dataTable and dataSet have been declared at the class-wide level as
  2. // private DataTable dataTable;
  3. // private DataSet dataSet;
  4.  
  5. DataRow row = dataTable.Rows [currRec];
  6.  
  7. row.BeginEdit ();
  8. row ["Title"]        = txtTitle.Text;
  9. row ["FirstName"]    = txtFirstName.Text;
  10. row ["MiddleName"]   = txtMiddleName.Text;
  11. row ["LastName"]     = txtLastName.Text;
  12. row ["Suffix"]       = txtSuffix.Text;
  13. row ["Phone"]        = txtPhone.Text;
  14. row ["EmailAddress"] = txtEmailAddress.Text;
  15. row.EndEdit ();
  16.  
  17. try { dataAdapter.Update (dataSet, "Person.Contact"); }
  18. catch (System.Runtime.InteropServices.ExternalException exc)
  19. {
  20.     MessageBox.Show (exc.Message + "\n\n" + currRec + "\n\"" + 
  21.         dataSet.Tables ["Person.Contact"].Rows [currRec] ["PasswordHash"].ToString () + "\"", 
  22.         "System.Runtime.InteropServices.ExternalException");
  23. }
  24. catch (Exception exc) { MessageBox.Show (exc.Message, "Exception"); }
  25.  
  26. try { dataSet.AcceptChanges (); }
  27. catch (Exception exc) { MessageBox.Show (exc.Message, "dataSet.AcceptChanges ();"); }
  28.  
When I edit and save an existing record (which already has a PasswordHash) to the locally resident DataSet and then to the database, it works fine (which of course means that the AdventureWorks sample database is not read-only). But when I try to save a new (inserted) record, even if I include a statement
Expand|Select|Wrap|Line Numbers
  1. row ["PasswordHash"] = "GylyRwiKnyNPKbC1r4FSqA5YN9shIgsNik5ADyqStZc=";
in the above Edit, I get the following System.Runtime.InteropServices.ExternalException message:
Cannot insert the value NULL into column 'PasswordHash', table 'AdventureWorks.Person.Contact'; column does not allow nulls.
INSERT fails.
The statement has been terminated.
I get this message despite the fact that the PasswordHash is displayed in the MessageBox as being in the Dataset, and the statement
Expand|Select|Wrap|Line Numbers
  1. dataSet.AcceptChanges ();
throws no exception!

Using SQL Server 2008 Management Studio Express, I can find no property of column PasswordHash that would account for this.

Can anybody tell me: how can I write to the PasswordHash column? (This is the most important question in this post, and what distinquishes it from my previous thread.)

Next question (for when I have the above issue resolved): although "GylyRwiKnyNPKbC1r4FSqA5YN9shIgsNik5ADyqStZc=" is a real password hash that I lifted from an already existing record (see above), I’m pretty sure I can’t just plunk it into a new record, because I notice that every record has a different password hash, which means every record has a different password. This seems very strange to me. What purpose could this serve? And more importantly: how can I generate valid password hashes for new records that have not (yet) had passwords associated with them?

Or perhaps I can make SQL Server Management Studio allow NULL in the PasswordHash column. I discovered this would be possible in SQL Server Management Studio via:

expand table | expand Columns | right-click PasswordHash column | click Modify | in lower right frame: toggle Allow Nulls from No to Yes

On doing so and then attempting to exit SQL Server Management Studio, I got a dialog box saying:
Save changes to the following items?
SQL Server Objects
<Server name>.AdventureWorks - Person.Contact
Clicking Yes elicited the following message:
Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.

Contact (Person)
SQL Server Management Studio's onboard Help says I can override the "Prevent saving changes that require the table to be re-created" setting via:

Tools | Options | Designers | Table and Database Designers | Prevent saving changes that require table re-creation

I can try this, but I wonder if it might be dangerous, under two possible scenarios:

Firstly, if for whatever reason the table can't be re-created, could I possibly destroy the original table in the process and then have to reinstall the AdventureWorks database? I don't want to have to do that, since for some unknown reason I had a very difficult time installing it the first time.

And secondly, I have received the following warning about allowing null password hashes:
These tables are usually related to one another. There are referential and domain integrity checks within the tables across the database. Although you might be able to change some of these, some of the relationships and checks might be broken because of your update.
In other words, the writer speculates that allowing null password hashes might compromise the relationships between tables. For that matter, I suppose the same might be said about using “fake” password hashes, as described above.

On the other hand, wouldn't a password hash be relevant only to applications that use passwords? All I want MY application to do is to edit, insert and delete records. It won't require any passwords. Is it really likely that relationships between tables could be compromised if null or “fake” password hashes are used?

For what it's worth, I'm working in a 32-bit environment with the following software:

SQL Server 2008 Express with Advanced Services
database: SQL2008 AdventureWorks (schema.table: Person.Contact)
SQL Server 2008 Management Studio Express
Visual C# 2008 Express
Mar 30 '09 #1
2 3865
ck9663
2,878 Recognized Expert Specialist
When I edit and save an existing record (which already has a PasswordHash) to the locally resident DataSet and then to the database, it works fine (which of course means that the AdventureWorks sample database is not read-only). But when I try to save a new (inserted) record, even if I include a statement
The error "INSERT fails." means you're inserting a new record, which you are. This happens when you're trying to specifically insert a NULL value on a column that does not allow NULL.

something like:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Person.Contact  (FirstName,  LastName, PasswordHash)
  2. values ('CLARK', 'KENT', NULL)
  3.  
The values could be coming from a SELECT statement as well.

or it could be that you missed that column. Something like:


Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Person.Contact  (FirstName,  LastName,)
  2. values ('CLARK', 'KENT')
  3.  
Try posting here your INSERT statement and let's see what we can do.


On the other hand, wouldn't a password hash be relevant only to applications that use passwords? All I want MY application to do is to edit, insert and delete records. It won't require any passwords. Is it really likely that relationships between tables could be compromised if null or “fake” password hashes are used?
The relationship is more of related to whatever keys join these tables. That means if you delete a record from Person.Contact it should be deleted to all other tables that are related to it. That's a little challenging to find it. Since ContactID is an IDENTITY, you will not be able to reuse the value. Which means even if you insert it back, the relationship of the rows is already broken.

Firstly, if for whatever reason the table can't be re-created, could I possibly destroy the original table in the process and then have to reinstall the AdventureWorks database? I don't want to have to do that, since for some unknown reason I had a very difficult time installing it the first time.
I'm not 100% sure. Why don't you create a new (workdb) database, copy the table that you want from AdventureWorks to that workdb and you can do anything you want with it.

-- CK
Mar 30 '09 #2
BobLewiston
93 New Member
ck9663:

Try posting here your INSERT statement and let's see what we can do.
Yeah, the INSERT statement was the issue. Problem resolved. Thanks for your help.
Apr 1 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1529
by: D Witherspoon | last post by:
When sending a dataset back to a dataadapter with an update command (SQL Stored Proc) i get an error saying missing paremeter for paramters that have their sourcefield a value of null. This will...
2
2864
by: Joe Fetters via .NET 247 | last post by:
Have googled and read the VS.NET documentation can't seem to getthe answer to the following. Environment: Framework 1.1 VB.NET WinForm Access database Using all automagic tools (DataAdapter...
13
2062
by: Doug Bell | last post by:
Hi, I thought I had this sorted this morning but it is still a problem. My application has a DataAccess Class. When it starts, it: Connects to a DB (OLE DB) If it connects it uses an...
11
2226
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
8
2673
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
6
13980
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
4
11151
by: George | last post by:
Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges(). Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and...
5
5027
by: George | last post by:
I have set DataAdapter.AcceptChangesDuringUpdate = true; However, I find that I still need to call AcceptChanges on the associated DataTable, DataTable.AcceptChanges(); Has anyone...
6
3018
by: BobLewiston | last post by:
When I try to save a new (inserted) record in an SQL database, I get the following System.Runtime.InteropServices.ExternalException message: I have to either find out how to insert an...
0
7380
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.