Visual Basic

Hi Friends, Post here your VB6.0(Intermediate) Question to get solution.
.


How to Connect your Application with Any SQL Server on Networks/Local

The first look of your application should be like this then you can save this all setting into your database/File once matching Connection string Application should display Main Page.
While Passing data on forms be sure to Authentication Type.

Source Code :
Public constr As String (Declared in Module)
Dim objnetwork
Private Sub ChkLogtype_Click()
If ChkLogtype.Value = 1 Then
ChkIntegSec = 1
ChkUsrInst = 1
Chkpersist = 1
Txtid.Enabled = False
Txtid.BackColor = vbRed
Txtpwd.Enabled = False
Txtpwd.BackColor = vbRed
Else
Txtid.Enabled = True
Txtid.BackColor = vbWhite
Txtpwd.Enabled = True
Txtpwd.BackColor = vbWhite
End If

End Sub

Private Sub Cmdclear_Click()
TxtPath.Text = ""
End Sub

Private Sub Cmdclose_Click()
End
End Sub

Private Sub Cmdconnect_Click()
On Error GoTo trap:
Dim con As New ADODB.Connection

con.Provider = "SQLOLEDB"
'con.ConnectionString = "server=GD130\SQLEXPRESS;initial catalog=master;trusted_connection=yes;user instance=true;Persist Security Info=False" 'constr
con.ConnectionString = constr

If con.State = 1 Then

con.Close
Else

con.Open
Lblstatus.Caption = "Connected Successfully.."
End If
Exit Sub
trap:
MsgBox "Error While." & Err.Description, vbCritical
End Sub

Private Sub CmdDB_Click()
Txtdb.Text = "master"
End Sub

Private Sub Cmddomain_Click()
Txtdomain.Text = objnetwork.userdomain
End Sub

Private Sub CmdPc_Click()
TxtPC.Text = objnetwork.ComputerName
End Sub

Private Sub Cmdprepare_Click()
Dim Intgsec, Usrinst, SecInfo, TrstCon As String
If ChkLogtype.Value = 1 Then
'Intgsec = "Integrated Security=True"
TrstCon = "trusted_connection=yes"
Usrinst = "User Instance=True"
SecInfo = "Persist Security Info=False"
constr = "Data source=" & Trim(TxtPC.Text) & ";Initial Catalog=" & Trim(Txtdb.Text) & ";" & TrstCon & ";" & SecInfo & ";" & Usrinst 'Intgsec
Else
constr = "Data source=" & Trim(TxtPC.Text) & ";Initial Catalog=" & Trim(Txtdb.Text) & ";user id=" & Trim(Txtid.Text) & ";Password=" & Trim(Txtpwd.Text)
End If
TxtPath.Text = constr
End Sub

Private Sub CmdWinUsr_Click()
TxtUser.Text = objnetwork.UserName
End Sub

Private Sub Form_Load()
Set objnetwork = CreateObject("WScript.Network")
End Sub

No comments:

Post a Comment