Kaskus

Tech

muse007Avatar border
TS
muse007
Koneksi Multiuser Client Server - VBnet & SQL Server 2000
Option Strict Off
Option Explicit On

Imports System.Data.SqlClient

Module KoneksiDatabase
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpSectionName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpSectionName As String, ByVal lpKeyName As String, ByVal lpValueUser As String, ByVal lpFileName As String) As Integer

Public Pass, Ser, User, DB As String

'------------------------------Deklarasi ke server----------------------------------------
Public Conn As SqlConnection
Public Da As SqlDataAdapter
Public Ds As DataSet
Public Cmd As SqlCommand
Public Rd As SqlDataReader
Public Str As String
Public Trans As SqlClient.SqlTransaction
Public IsConError As Boolean
'-----------------------------------------------------------------------------------------

Public Sub Koneksi() ' Koneksi Ke Server
Try
Pass = ReadIniValue(My.Application.Info.DirectoryPath & "\Konfigurasi Server.ini", "konfigurasi", "Password")
User = ReadIniValue(My.Application.Info.DirectoryPath & "\Konfigurasi Server.ini", "konfigurasi", "User")
DB = ReadIniValue(My.Application.Info.DirectoryPath & "\Konfigurasi Server.ini", "konfigurasi", "Database")
Ser = ReadIniValue(My.Application.Info.DirectoryPath & "\Konfigurasi Server.ini", "konfigurasi", "Server")

Str = "Data Source=SQLOLEDB.1;Password=" & Pass & ";Persist Security Info=True;User ID=" & User & ";Initial Catalog=" & DB & ";Data Source=" & Ser & ""
Conn = New SqlConnection(Str)
If Conn.State = ConnectionState.Closed Then
Conn.Open()
End If

Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Fatal Error")
End Try
End Sub

Public Function ReadIniValue(ByRef INIpath As String, ByRef KEY As String, ByRef Variable As String) As String
Dim NF As Short
Dim Temp As String
Dim LcaseTemp As String
Dim ReadyToRead As Boolean
AssignVariables:
NF = FreeFile
ReadIniValue = ""
KEY = "[" & LCase(KEY) & "]"
Variable = LCase(Variable)
EnsureFileExists:
FileOpen(NF, INIpath, OpenMode.Binary)
FileClose(NF)
LoadFile:
FileOpen(NF, INIpath, OpenMode.Input)
While Not EOF(NF)
Temp = LineInput(NF)
LcaseTemp = LCase(Temp)
If InStr(LcaseTemp, "[") <> 0 Then ReadyToRead = False
If LcaseTemp = KEY Then ReadyToRead = True
If InStr(LcaseTemp, "[") = 0 And ReadyToRead = True Then
If InStr(LcaseTemp, Variable & "=") = 1 Then
ReadIniValue = Mid(Temp, 1 + Len(Variable & "="))
FileClose(NF) : Exit Function
End If
End If
End While
FileClose(NF)
End Function
End Module


klo masih bingung tanya aja ya emoticon-I Love Indonesia (S)
0
1.7K
1
GuestAvatar border
Komentar yang asik ya
Urutan
Terbaru
Terlama
GuestAvatar border
Komentar yang asik ya
Komunitas Pilihan