Solved

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

Posted on 2011-09-18
10
410 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

691 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