Solved

Changing password at runtime

Posted on 2007-11-13
10
253 Views
Last Modified: 2010-04-23
Hello,
I have my VB.NET application, developed with visual web developer,  which access SQL Server DB using connection strings defined in the web.config file.

Now, I have to give the user, ability to change their passwords of their SQL Server DB accounts.  I can throw them a screen asking them to change their passwords but how can I propogate the new password to the database and make the changes in the SQL Server itself?

Thanks.
0
Comment
Question by:pavanbh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 
LVL 14

Expert Comment

by:cezarF
ID: 20277304
call the sp_password SQL server stored procedure

sp_password [ [ @old = ] 'old_password' , ]

{ [ @new =] 'new_password' }

[ , [ @loginame = ] 'login' ]
0
 
LVL 14

Expert Comment

by:cezarF
ID: 20277342
something like this ...

Dim sqlCon As SqlConnection = = New SqlConnection("your connection string")
Dim sqlCom As SqlCommand = sqlCon.CreateCommand()

SqlCom.CommandType = CommandType.StoredProcedure
sqlCom.CommandText = "sp_password"
SqlCom.CommandTimeout = 500

SqlCom.Parameters.Clear()
sqlCom.Parameters.Add(New SqlParameter("@old", SqlDbType.VarChar, 20))
sqlCom.Parameters.Add(New SqlParameter("@new", SqlDbType.VarChar, 20))
sqlCom.Parameters.Add(New SqlParameter("@loginame", SqlDbType.VarChar, 20))

sqlCom.Parameters("@old").value = "oldpassword"
sqlCom.Parameters("@new").value = "newpassword"
sqlCom.Parameters("@loginame").value = "loginname"

sqlCom.ExecuteNonQuery()

If sqlCon.State = ConnectionState.Closed Then sqlCon.Open()

0
 
LVL 14

Expert Comment

by:cezarF
ID: 20277345
sorry , change ..

Dim sqlCon As SqlConnection = = New SqlConnection("your connection string")

to

Dim sqlCon As SqlConnection = New SqlConnection("your connection string")
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 14

Accepted Solution

by:
cezarF earned 200 total points
ID: 20277388
argh... this is the correct one.

Dim sqlCon As SqlConnection =  New SqlConnection("your connection string")
Dim sqlCom As SqlCommand = sqlCon.CreateCommand()

SqlCom.CommandType = CommandType.StoredProcedure
sqlCom.CommandText = "sp_password"
SqlCom.CommandTimeout = 500

SqlCom.Parameters.Clear()
sqlCom.Parameters.Add(New SqlParameter("@old", SqlDbType.VarChar, 20))
sqlCom.Parameters.Add(New SqlParameter("@new", SqlDbType.VarChar, 20))
sqlCom.Parameters.Add(New SqlParameter("@loginame", SqlDbType.VarChar, 20))

sqlCom.Parameters("@old").value = "oldpassword"
sqlCom.Parameters("@new").value = "newpassword"
sqlCom.Parameters("@loginame").value = "loginname"

If sqlCon.State = ConnectionState.Closed Then sqlCon.Open()

sqlCom.ExecuteNonQuery()
0
 

Author Comment

by:pavanbh
ID: 20277496
Thanks for the quick reply...

but when I paste the code in my visual web developer, it is not recognizing the SqlConnection, SqlCommand, CommandType, SqlParamater or the ConnectionState objects....Should I enable something in the visual web developer for it to recognize this? Is this all ADO, 'coz I am not using ADO

I use

dim ds as New SqlDataSource
ds.ConnectionString= ConfigurationManager.ConnectionStrings("MyConnString").ToString


0
 
LVL 14

Expert Comment

by:cezarF
ID: 20277508
yes its ADO

add
Imports System.Data
Imports System.Data.SqlClient


0
 

Author Comment

by:pavanbh
ID: 20277574
Thanks again.

Where should I put these 2 statements.My code starts with

<%@ Page Language="VB" MasterPageFile="~/Master.master" Title="Untitled Page" %>

<script runat="server">
   
    Dim ds As New SqlDataSource
    Dim ID As New Integer
   

Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
       
End Sub

Thanks
0
 
LVL 14

Expert Comment

by:cezarF
ID: 20277605
at the top of your page's code-behind  (e.g.: yourpage.aspx.vb)
0
 

Author Comment

by:pavanbh
ID: 20280158
Thanks cezarF. That works perfectly as expected.
0
 
LVL 14

Expert Comment

by:cezarF
ID: 20280327
thanks! :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question