How to connect to a database using a text file

  • Thread starter Thread starter Houssem12
  • Start date Start date
H

Houssem12

Guest
Hello

i created a class that serve what i want but it look to me not professionel so i want something more

Imports System.IO
Imports System.Data.SqlClient
Public Class Class1
Public Function MySub() As String
Dim sr As New StreamReader("C:\Houssem\connection.ini")
Dim line As String = sr.ReadLine
Dim line2 As String = sr.ReadLine
If line = "[SERVER]" Then
line2 = line2.Substring(4)
End If
Return (line2)
End Function
Public Function mysub2() As String
Dim sr As New StreamReader("C:\Houssem\connection.ini")
Dim line As String = sr.ReadLine
Dim line1 As String = sr.ReadLine
Dim line2 As String = sr.ReadLine
If Not line2 = "" Then
line2 = line2.Substring(14)
End If
Return (line2)
End Function
Public Function cn() As SqlConnection
Dim cnn As New SqlConnection("server='" & MySub() & "';database='" & mysub2() & "';integrated security=true;Connection Timeout=60")
Return cnn
End Function
End Class

i want place in text file some word to identify the server name for exemple

[Database File]

server:SDZ

Database:SDZ

so if i open the file and change SDZ i can connect to any database i want without recode the line of connection and its look not good for security

please help

Continue reading...
 
Back
Top