Solved

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

Posted on 2011-09-18
10
407 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
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…

829 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