Solved

Changing password at runtime

Posted on 2007-11-13
10
247 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
  • 7
  • 3
10 Comments
 
LVL 14

Expert Comment

by:cezarF
Comment Utility
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
Comment Utility
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
Comment Utility
sorry , change ..

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

to

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

Accepted Solution

by:
cezarF earned 200 total points
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Expert Comment

by:cezarF
Comment Utility
yes its ADO

add
Imports System.Data
Imports System.Data.SqlClient


0
 

Author Comment

by:pavanbh
Comment Utility
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
Comment Utility
at the top of your page's code-behind  (e.g.: yourpage.aspx.vb)
0
 

Author Comment

by:pavanbh
Comment Utility
Thanks cezarF. That works perfectly as expected.
0
 
LVL 14

Expert Comment

by:cezarF
Comment Utility
thanks! :)
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now