Using the following code and trying to allow the end user to specify the values for the connection string for an app that inports .csv to a specified location. App fails to run due to the fact that it tries to initialize connection string on program run resulting in NULL values. Is there any way I can prevent this and make this work?
vb.net Code:
Imports System.Data.SqlClient Imports System.IO Imports System.Configuration Imports System.Data.Common.DbConnection Public Class csvUpdate 'connection string Public WithEvents con As New SqlConnection _ ("Data Source=" + TxtServer.Text + ";Initial Catalog=" + TxtCat.Text + ";Integrated Security=True;Asynchronous Processing=True") Public WithEvents var As New SqlConnection _ ("Data Source=" + TxtServer.Text + ";Initial Catalog=" + TxtCat.Text + ";User Id =" + TxtUser.Text + ";Password=" + TxtPass.Text + ";Asynchronous Processing=True") Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Height = 172 End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCSV.Click If TxtTable.Text <> "" Then OpenFileDialog1.Title = "Open a Text File" OpenFileDialog1.Filter = "Comma Delimited(*.csv)|*.csv" OpenFileDialog1.DefaultExt = ".csv" OpenFileDialog1.InitialDirectory = "C:\" OpenFileDialog1.ShowDialog() If ChkAD.Checked = True Then 'readcsvAD() Else 'readcsvUP() End If Else TxtTable.Focus() End If End Sub Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkAD.CheckedChanged If Me.Height < 242 Then Me.Height = 243 Else Me.Width = 144 Me.Height = 172 End If End Sub End Class
Thanks!




Reply With Quote
