Community discussion forum

Help! how do I Configure the DB connection settings during setup?

  • 8 months ago

     

    Hi, I am a VB.NET beginner and am trying to connect to a backend db ( SQL serverf 2000 ) I have currently hard coded this in my program, but have come to realise that that was not a good idea, instead it would have been better to variablise it somehow and let the admins that will install the application populate the backend server during setup.

    my setup is an msi setup that I let VS2005 create for me - I have tried using .config files but failed as for some reason I could not see anything in the .config file from within my code or reference it.

    I see applications every day where during the msi setup ( possibly as a public property ) you can add the db server details which is read from within the code, can someone please assist me or point me to how to do this?

    Many Thanks in advance. Edit/Delete Message

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 8 months ago

    in app.config file   copy below code  and set ur database settings

    <
    connectionStrings>

    <add name="Dbase" connectionString="Data Source= servr name;initial catalog=database; User id=test; Password=test"/>

    </connectionStrings>

  • 7 months ago

     how do I reference the app.config from within my code?

  • 6 months ago

    Mr Argoran, See this code. This will connect to database without any parameters. What all you require is Database name. See, When you are going to work with Database, better create your own database.Create Database. When creating database in your hands, pre define with a name and append to Connection string. Well. Any doubts on this are welcome.

    Imports System.Data.SqlClient

    Imports System.Data

    Public Class Form1

    Dim cn As New SqlConnection("Integrated Security=TRUE;Persist Security Info=FALSE;")

    Dim cmd As New SqlCommand

    Dim da As New SqlDataAdapter

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    cn.Open()

    If cn.State = ConnectionState.Open Then

    Button1.Text = "Connected"

    Else

    Button1.Text = "NOT Connected"

    End If

    End Sub

    End Class

  • 6 months ago

     Thank you I don't know why I didn't think of that even though it's quite obvious and easy to setup -- Many Thanks !!!!!

Post a reply

Enter your message below

Sign in or Join us (it's free).