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

  • 12 years 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
  • 12 years ago

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


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


  • 12 years ago

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

  • 12 years 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


    If cn.State = ConnectionState.Open Then

    Button1.Text = "Connected"


    Button1.Text = "NOT Connected"

    End If

    End Sub

    End Class

  • 12 years 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).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Memory is like an orgasm. It's a lot better if you don't have to fake it.” - Seymour Cray