JURASOURCE | WEBLOG | |
 

 

Like, uh, whatever, I guess

 

 
  Wednesday, May 12, 2004
 
    [3:26:49 PM]

.NET SqlConnection Revelation



Revelation may be too strong a word, but that's what it felt like when I figured out this problem earlier:


       
  1. Create a SqlConnection, _con

  2.    
  3. Set _con.ConnectionString to my connection string

  4.    
  5. Open connection

  6.    
  7. Do some stuff

  8.    
  9. Close connection, no need for it to be open if it's not being used? (In this application this is the best approach)

  10.    
  11. Re-open connection

  12.    
  13. Try and do some stuff, but get an Error: Access denied message

  14.    
  15. Throw up hands in dispair after realising that the password parameter has been dropped from the connection string... Why why why?


Thankfully there's a very simple solution to this, just add Persist Security Info=True to the connection string, and the password will be, well, persisted, regardless of how many times the connection is opened and closed.



Ref: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlConnectionClassConnectionStringTopic.asp


    |
 
 


ARCHIVES
 
November 2003
January 2004
February 2004
March 2004
April 2004
May 2004
June 2004
 
     

This page is powered by Blogger. Isn't yours?  Weblog Commenting and Trackback by HaloScan.com