Solved

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

Posted on 2011-09-18
10
408 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
[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
  • 5
  • 4
10 Comments
 
LVL 15

Expert Comment

by:x77
ID: 36556178
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
ID: 36556183
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
ID: 36556189
oke but how can i set the parameters?

And if i use a auto update program to install

Thank
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 15

Expert Comment

by:x77
ID: 36556205
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
ID: 36556212
Note.:

  You can drag a Mdb File from Explorer over Application Icon.
  Then You are usign application with mdb file name as argument.
0
 

Author Comment

by:prinsbj
ID: 36556219
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
ID: 36556268
 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
ID: 36556383
Hello x77,

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

Thank
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36570417
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
ID: 36593540
Hello X77!

It works great.

Thank you.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display

740 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