Site Search:
Sign in | Join | Help

How to get connection data from VS Tools

Last post 10-08-2008 10:40 AM by Tom Garth. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 08-27-2007 5:24 PM

    How to get connection data from VS Tools

    This code will allow you to get connection data from VS Tools

    'gather some global variables
    oUser.Database = Dynamics.Globals.IntercompanyId.Value
    oUser.UserID = Dynamics.Globals.UserId.Value
    oUser.Password = Dynamics.Globals.SQLPassword 
    
    
    'get the server
    Dim backup As Microsoft.Dexterity.Applications.DynamicsDictionary.SyBackupRestoreForm
    backup = Microsoft.Dexterity.Applications.Dynamics.Forms.SyBackupRestore
    oUser.Server = backup.Functions.GetServerNameWithInstance.Invoke
    
    
    oUser.ConnectionString = "Data Source=" & oUser.Server & ";Integrated Security=SSPI;Initial Catalog=" & oUser.Database 
    
    
     <font size="2">

    This class makes use of the above info, and genereates a connections string dynamically when you use it.

    Imports Microsoft.Dexterity.Applications
    Public Class user
        Public ReadOnly Property Database() As String
            Get
                Return Dynamics.Globals.IntercompanyId.Value()
            End Get
        End Property
        Public ReadOnly Property UserID() As String
            Get
                Return Dynamics.Globals.UserId.Value
            End Get
        End Property
        Public ReadOnly Property ConnectionString() As String
            Get
                Return "Data Source=" & Me.server & ";Integrated Security=SSPI;Initial Catalog=" & Me.Database
    
    
            End Get
        End Property
        Public ReadOnly Property server()
            Get
                'Declare an instance of the Microsoft Dynamics GP syBackupRestore 
                'form in which the function resides.
                Dim backup As Microsoft.Dexterity.Applications.DynamicsDictionary.SyBackupRestoreForm
                backup = Microsoft.Dexterity.Applications.Dynamics.Forms.SyBackupRestore
    
    
                'Invoke the form-level function.  
                Return backup.Functions.GetServerNameWithInstance.Invoke()
    
    
            End Get
        End Property
    End Class
    
    
     

    Steve Gray, MCDBA
    Technical Editor
    steve@VSToolsForum.com
    • 216.77.101.2
  • 11-01-2007 3:10 AM In reply to

    Re: How to get connection data from VS Tools

     Hi ,

    I try to run ur code and I got the error 'The Specificied module could not be found' FileNotFound Exception

    Anyidea?

    Tommy 

     

    • 203.125.138.46
  • 11-01-2007 7:48 AM In reply to

    Re: How to get connection data from VS Tools

    Can you be more specific? Trace through the code and tell me exactly which line is giving the error.

    Steve Gray, MCDBA
    Technical Editor
    steve@VSToolsForum.com
    • 216.77.101.2
  • 11-01-2007 10:07 PM In reply to

    Re: How to get connection data from VS Tools

     Hi .. here is my code...

    Imports DynamicsGPAddin
    Module modMain
        Public Sub Main()
            Dim aa As New GPAddIn
            Dim tmpString As String
            tmpString = aa.UserID

    I build the Addin dll and use it my eConnect project. I just want to test whether I can call GP forms through my eConnect project.

    When I read the pdf file comes with the GP 10 VS Tools SDK, this addin tools dll must be placed in GP AddIn folder and run through from GP Interface.

    So, it's looks like I can't run this AddIn attached with other .Net projects? Please explain me. I'am new at VS tools for GP

    Tommy 

     

     

    • 203.125.138.46
  • 11-01-2007 11:46 PM In reply to

    Re: How to get connection data from VS Tools

     Hi...

    What I mean is ... I just want to run my AddIn from my another external project . In that case, do I need to open GP from my external project?

    And how can I run my AddIn automically run when GP is start running...

    Please reply asap... I'm stuk ... :(

    Tommy 

    • 203.125.138.46
  • 11-02-2007 8:09 AM In reply to

    Re: How to get connection data from VS Tools

    Nope, can't do that, sorry. VS Tools for Dynamics code can only be run from inside of Dynamics, AFAIK.

    Steve Gray, MCDBA
    Technical Editor
    steve@VSToolsForum.com
    • 216.77.101.2
  • 06-26-2008 12:06 PM In reply to

    Re: How to get connection data from VS Tools

    Steve,

     

    Is there any security concern running this as a "normal" user and calling the syBackupRestore form?

     

    Thanks,

     

    New GP Developer

    • 66.193.165.66
  • 06-26-2008 12:54 PM In reply to

    Re: How to get connection data from VS Tools

    Not that I know of... but that form give me trouble some times. I never thought about security...

    Steve Gray, MCDBA
    Technical Editor
    steve@VSToolsForum.com
    • 216.64.79.2
  • 06-26-2008 12:58 PM In reply to

    Re: How to get connection data from VS Tools

     

    Have you found any other ways since your initial posting to get the current company connection string without using that form?

    • 66.193.165.66
  • 08-11-2008 3:00 PM In reply to

    Re: How to get connection data from VS Tools

    here is the class that I'm currently using:

     Imports Microsoft.Dexterity.Applications
    
    
    
    Public Class user
    
    
        Public Shared ReadOnly Property Database() As String
            Get
                Return Dynamics.Globals.IntercompanyId.Value
            End Get
        End Property
    
    
        Public Shared ReadOnly Property UserID() As String
            Get
                'returns the Dynamics userid. Not much good without the password
                Return Dynamics.Globals.UserId.Value
            End Get
        End Property
    
    
        Private Shared ReadOnly Property password() As String
            Get
                'returns the UNENCRYPTED user Dynamics password. Useless
                Return Dynamics.Globals.SqlPassword.Value
            End Get
        End Property
    
    
        Public Shared ReadOnly Property ConnectionString() As String
            Get
                If user.Database = "" Then
                    Return ""
                End If
    
    
                Return "Server=" & System.Configuration.ConfigurationManager.AppSettings("server") & ";Database=" & user.Database & _
                    ";User ID=myUser" & _
                    ";Password=myPass" & _
                    ";Trusted_Connection=False; "
            End Get
        End Property
    End Class

    Steve Gray, MCDBA
    Technical Editor
    steve@VSToolsForum.com
    • 216.64.79.2
  • 08-21-2008 4:21 PM In reply to

    Re: How to get connection data from VS Tools

    Hi Steve,

    I see that you are hard-coding the user id and password… I take it that there is no way to get a db connection from the objects or an encrypted password that would work.

    ";User ID=myUser" & _
                    ";Password=myPass" & _
                    ";Trusted_Connection=False; "

    • 74.223.159.175
  • 08-22-2008 8:15 AM In reply to

    Re: How to get connection data from VS Tools

    https://mbs.microsoft.com/knowledgebase/KBDisplay.aspx?scid=kb;en-us;912960

     

    As it happens, David Musgrave from Microsoft just sent me the above link, it describes a process where you can get a connection. It would not be my first choice, but the environment that I work in is not real security concious. I can see where it would have it's place.

     

    Bear in mind that the password that you get in Dynamics is encrypted. Even if Dynamics give you the unencrypted password, you can't use it because it needs to be encrypted again to use it. Problem.

     

    I know that my suggestion above is lazy...

    Steve Gray, MCDBA
    Technical Editor
    steve@VSToolsForum.com
    • 71.100.135.32
  • 10-08-2008 10:40 AM In reply to

    Re: How to get connection data from VS Tools

    For the server you can also go to the registry with the DSN name in hand.

    Server = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\" & DynGlobals.SqlDataSourceName & "\", "Server", "")

    • 63.27.58.168
Page 1 of 1 (13 items)