Solved

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

Posted on 2011-09-18
10
409 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
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

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