Solved

Changing password at runtime

Posted on 2007-11-13
10
251 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
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
Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

763 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