Solved

Changing password at runtime

Posted on 2007-11-13
10
250 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 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