Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Changing password at runtime

Posted on 2007-11-13
10
Medium Priority
?
254 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 14

Accepted Solution

by:
cezarF earned 800 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

705 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