dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

SQL PasswordHash NULL problem - Microsoft SQL Server

This is a discussion on SQL PasswordHash NULL problem - Microsoft SQL Server ; 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: Code: // here dataTable and dataSet have been declared at the class-wide level ...


Home > Database Forum > Microsoft SQL Server > SQL PasswordHash NULL problem

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 03-29-2009, 10:08 PM
Database Newbie
 
Join Date: Mar 2009
Posts: 1
thedougster is on a distinguished road
Default SQL PasswordHash NULL problem

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:
Code:
// here dataTable and dataSet have been declared at the class-wide level as
// private DataTable dataTable;
// private DataSet dataSet;

DataRow row = dataTable.Rows [currRec];

row.BeginEdit ();
row ["Title"]        = txtTitle.Text;
row ["FirstName"]    = txtFirstName.Text;
row ["MiddleName"]   = txtMiddleName.Text;
row ["LastName"]     = txtLastName.Text;
row ["Suffix"]       = txtSuffix.Text;
row ["Phone"]        = txtPhone.Text;
row ["EmailAddress"] = txtEmailAddress.Text;
row.EndEdit ();

try { dataAdapter.Update (dataSet, "Person.Contact"); }
catch (System.Runtime.InteropServices.ExternalException exc)
{
    MessageBox.Show (exc.Message + "\n\n" + currRec + "\n\"" + 
        dataSet.Tables ["Person.Contact"].Rows [currRec] ["PasswordHash"].ToString () + "\"", 
        "System.Runtime.InteropServices.ExternalException");
}
catch (Exception exc) { MessageBox.Show (exc.Message, "Exception"); }
            
try { dataSet.AcceptChanges (); }
catch (Exception exc) { MessageBox.Show (exc.Message, "dataSet.AcceptChanges ();"); }
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. But when I try to save a new (inserted) record, even if I include a statement
Code:
row ["PasswordHash"] = "GylyRwiKnyNPKbC1r4FSqA5YN9shIgsNik5ADyqStZc=";
in the above Edit, I get the following System.Runtime.InteropServices.ExternalException message:
Quote:
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
Code:
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 what’s going on here?

Next question (for when I have the above issue resolved): although "GylyRwiKnyNPKbC1r4FSqA5YN9shIgsNik5ADyqStZc=" is a real PasswordHash that I lifted from an already existing record (see above), I don’t really know if I can just plunk it into a new record. I found a code snippet to generate a PasswordHash, but it appears to need the password itself to create the PasswordHash. I don’t know why an individual column within an individual table would need an individual password, so I guess what’s needed is the password for the entire database. But my database doesn’t have a password; since the database is resident on my computer and I’m the only user, I just use Windows Authentication. Does anyone know what I should do? Or maybe I can just put anything in this column?

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:
Quote:
Save changes to the following items?
SQL Server Objects
.AdventureWorks - Person.Contact
Clicking Yes elicited the following message:
Quote:
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. 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 besides, I want to have the option to implement encryption later, and I suspect I might not be able to if I allowed PasswordHash to be NULL. (Anybody know if that’s true?)

Also, I have been warned that if I do this I might “break something”. I don’t see how this would affect the relationships between tables. Any opinions?

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
Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 06:51 PM.