Solved

How to build a loginform in vb.net with a addtional function to select a database?

Posted on 2011-09-18
10
405 Views
Last Modified: 2012-06-27
Can somebody help me with a loginform that has a extra function to select a database.

So i want that user can login in the production db or in the testdb.

I use sql 2005 en vb.net in Visual studio 2008

Thanks for your reactions

Bart
0
Comment
Question by:prinsbj
  • 5
  • 4
10 Comments
 
LVL 15

Expert Comment

by:x77
Comment Utility
I use CommandLine to do it.

Normal User uses a icon to access application.
I Inspect CommandLine when Programa Start and change Connection String if CommandLine has Apropiate Parameters.

I can creata an alternate Icon to Access to Test and change Name to "Test MyProgram"
0
 
LVL 15

Expert Comment

by:x77
Comment Utility
Note. Is important to Change the MainForm.Text (Caption) to indicate Test Connection.
This is used for Test the program, but also for formation.
0
 

Author Comment

by:prinsbj
Comment Utility
oke but how can i set the parameters?

And if i use a auto update program to install

Thank
0
 
LVL 15

Expert Comment

by:x77
Comment Utility
On this Sample, I use OleDb.

I connect to Oracle Production database when Environment.GetCommandLineArgs are empty.

I Use Parameter values as a Path to a Ms Access Database as Test Database.

DbTxt variable is used to show current Database on MainForm.
Public Function GetDbConnection() As OleDbConnection
      Dim s = Environment.GetCommandLineArgs, CnStr As String, cn As OleDbConnection = Nothing
      Dim LocalDb = s.Length > 1
      If LocalDb Then
        DbTxt = s(1)
        CnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DbTxt
      Else
        DbTxt = "Oracle"
        CnStr = My.Settings.CnStr & Decode(My.Settings.Pwd)
      End If
      Try
          cn = New OleDbConnection(CnStr)
          cn.Open()
          If LocalDb Then
             IsReten = True
             IsJt = True
          Else
             Dim cmd As New OleDbCommand("Select Prv from Priv Where NtUsr=?", cn)
             cmd.Parameters.AddWithValue(Nothing, Environment.UserName.ToUpper)
             Dim Prv = cmd.ExecuteScalar
             If Prv IsNot DBNull.Value Then
                Dim v = CInt(Prv)
                If (v And PrivPrj.Adm) > 0 Then IsAdm = True
                If IsAdm OrElse (v And PrivPrj.Reten) > 0 Then IsReten = True
                If IsReten OrElse (v And PrivPrj.JT) > 0 Then IsJt = True
             End If
          End If
      Catch ex As Exception
        MessageBox.Show(ex.Message, "Conexión Base de datos")
        cn = Nothing
      End Try
      Return cn
  End Function

Open in new window

0
 
LVL 15

Expert Comment

by:x77
Comment Utility
Note.:

  You can drag a Mdb File from Explorer over Application Icon.
  Then You are usign application with mdb file name as argument.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:prinsbj
Comment Utility
Thank you for sending this script,

I see you us decode for your password how can i us that also?
0
 
LVL 15

Accepted Solution

by:
x77 earned 500 total points
Comment Utility
 Private Cryptor As New RijndaelManaged _
     With {.IV = New Byte() {...}, _
           .Key = New Byte() {...}}

  Public Function Decode(ByVal Key As String) As String
     Dim bf = System.Convert.FromBase64String(Key)
     bf = Cryptor.CreateDecryptor().TransformFinalBlock(bf, 0, bf.Length)
     Return UTF8.GetString(bf)
  End Function

Note.: I Replace Cryptor Keys with elipsis "..."
You need use your own keys for encriptation.
You can run the program a first time without those values, then Program generates random valid values.
Dump it and hardcode it to your Program.


  Public Function Encode(ByVal Key As String) As String
     Dim BF = UTF8.GetBytes(Key)
     Return System.Convert.ToBase64String(Cryptor.CreateEncryptor().TransformFinalBlock(BF, 0, BF.Length))
  End Function


This method allow generate a encripted string to save on application Settings.
I use it on Debug:

  Debug.print Encode("MyPassword")
0
 

Author Comment

by:prinsbj
Comment Utility
Hello x77,

When i'm back home i'll test it and let you know.

Thank
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
One option would be to use a setting in the app.config file and use two connection strings. Depending on this setting(RunInTestMode), you can use either Live or Test connection string.
0
 

Author Closing Comment

by:prinsbj
Comment Utility
Hello X77!

It works great.

Thank you.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

10 Experts available now in Live!

Get 1:1 Help Now