Hello Friends, I am writing a method for connection named "connect" in vb.Net, the Connection String is OK. But giving exception. The Codes are below: Public Function Connect() As Integer con = New SqlClient.SqlConnection--------------------> Dim Servername As String Dim UserID As String Dim Password As String Dim Databasename As String Dim DB As Integer Environment.CurrentDirectory = Application.StartupPath Servername = ReadfromServerIni(Environment.CurrentDirectory & "\ServerConfig.ini", "ServerName", "Server") UserID = ReadfromServerIni(Environment.CurrentDirectory & "\ServerConfig.ini", "UserName", "ID") Password = ReadfromServerIni(Environment.CurrentDirectory & "\ServerConfig.ini", "UserName", "Pass") Databasename = ReadfromServerIni(Environment.CurrentDirectory & "\ServerConfig.ini", "DatabaseName", "Name") con.ConnectionString = ("Data source=" & Servername & ";uid=" & UserID & ";pwd=" & Password & ";Initial Catalog=" & Databasename & ";TimeOut=500;") ' Through Local Conecctivity Try If DB = 1 Then con.Open() Else IsRestoreDB = MsgBox("Database not Found! " & vbNewLine & "Would you like to restore the database.", MsgBoxStyle.YesNo) If IsRestoreDB = 6 Then frmDatabaseRestore.Show() Else IsRestoreDB = 0 End End If End If Catch ex As Exception MsgBox("A Problem occured due to make connection with Database", MsgBoxStyle.Information) End Try End Function Connect String is below: <connectionStrings> <addname="NGO.My.MySettings.NGOConnectionString"connectionString="Data Source=Noor-PC\SQLExpress;Initial Catalog=NGO;User ID=sa;Password=noor123"providerName="System.Data.SqlClient"/> </connectionStrings> Please help me if any knowledge about it. Thanks & Regards
Use the example code from MSDN: Using connection As New SqlConnection(connectionString) Dim command As New SqlCommand(queryString, connection) command.Connection.Open() command.ExecuteNonQuery() End Using