TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rajavel G
NA
95
44.2k
Methods to call a connection in visual studio 2012(c#,vb)
Nov 30 2016 1:22 AM
this is one method:
Create module for connection and attach a text file in debug folder.Have you know about any other.please in brief..
Imports System.IO
Imports System.Net
Imports System.Net.WebClient
Imports System.Text.RegularExpressions
Imports System.Net.Mail
Module modConn
Public conn As New SqlClient.SqlConnection
Public cmd As New SqlClient.SqlCommand
Public reader As SqlClient.SqlDataReader
Public adapter As SqlClient.SqlDataAdapter
Public SQL As String
Public strServer As String
Public strDbase As String
Public strUser As String
Public strPass As String
Public items As ListViewItem
Public Item As ListViewItem
Public FormName As String
Public FunctionName As String
Public ExceptionName As String
Public stadminname As String
Public stadminpassword As String
Dim FileText As String
Dim filelines As String()
Dim oneline As String()
Dim secondline As String()
Dim thirdline As String()
Dim fourthline As String()
Dim fifthline As String()
Dim sixthline As String()
Dim SeparatorChar As String = ":"
Public ShopName As String = ""
Dim server, user, password, database, adminname, adminpassword As String
Dim mail As New MailMessage
Public Sub conecDB()
Try
FileText = My.Computer.FileSystem.ReadAllText(My.Application.Info.DirectoryPath & "\serversettings.txt")
filelines = FileText.Split(CChar(Environment.NewLine))
oneline = filelines(0).Split(CChar(SeparatorChar))
secondline = filelines(1).Split(CChar(SeparatorChar))
thirdline = filelines(2).Split(CChar(SeparatorChar))
fourthline = filelines(3).Split(CChar(SeparatorChar))
fifthline = filelines(4).Split(CChar(SeparatorChar))
sixthline = filelines(5).Split(CChar(SeparatorChar))
server = oneline(1)
database = secondline(1)
user = thirdline(1)
password = fourthline(1)
adminname = fifthline(1)
adminpassword = sixthline(1)
strServer = server 'This is the server IP/Server name. If server is intalled on your local machine, your IP should be 127.0.0.1 or you may use localhost
strDbase = database 'Database name
strUser = user 'Database user
strPass = password 'pwd
stadminname = adminname
stadminpassword = adminpassword
If conn.State <> ConnectionState.Open Then conn.ConnectionString = "Data Source=" & strServer.Trim & ";Initial Catalog=" & strDbase.Trim & ";MultipleActiveResultSets=False;User ID=" & strUser.Trim & ";Password=" & strPass
If conn.State <> ConnectionState.Open Then conn.Open()
Catch ex As Exception : Error_Function(ex.Message, "CONNECTION STRING", "conecDB") : End Try
End Sub
Public Sub closeDB()
If conn.State <> ConnectionState.Closed Then conn.Close()
End Sub
Public Sub initCMD()
With cmd
.Connection = conn
.CommandType = CommandType.Text
.CommandTimeout = 0
End With
End Sub
Public Sub admin(ByVal adname As String, ByVal adpass As String)
If stadminname = adname And stadminpassword = adpass Then
MessageBox.Show("Incorrect")
End If
End Sub
Public Sub execComDB(ByVal PstrSQL As String)
Try
With cmd
.CommandText = PstrSQL
.ExecuteNonQuery()
End With
Catch ex As Exception
End Try
End Sub
Public Sub Error_Function(ByVal ErrorStrings As String, ByVal FormNames As String, ByVal FunctionNames As String)
If Not FunctionNames = "LOGIN" Then
MsgBox("Error Code: " & ErrorStrings & vbNewLine & vbNewLine & "Screen Name: " & FormNames & vbNewLine & vbNewLine & "Function Name: " & FunctionNames, MsgBoxStyle.Information, ShopName)
End If
Try
Dim SystemName As String = My.Computer.Name
Dim IPADDRESS As String = System.Net.Dns.GetHostByName(SystemName).AddressList(0).ToString
Dim OperatingSystem As String = My.Computer.Info.OSFullName
Dim ErrorInfoTxt As New RichTextBox
ErrorInfoTxt.Text = "ERROR OR NAME :" & ErrorStrings & vbNewLine
ErrorInfoTxt.Text += "FORM NAME :" & FormName & vbNewLine
ErrorInfoTxt.Text += "FUNCTION :" & FunctionName & vbNewLine
ErrorInfoTxt.Text += "SYSTEM NAME :" & SystemName & vbNewLine
ErrorInfoTxt.Text += "IP ADDRESS :" & IPADDRESS & vbNewLine
ErrorInfoTxt.Text += "MODEM IP ADDRESS :" & IPADDRESS & vbNewLine
ErrorInfoTxt.Text += "OPREATING SYSTEM :" & OperatingSystem & vbNewLine
Catch ex As Exception
End Try
End Sub
Public Function CheckForInternetConnection() As Boolean
Try
Using client = New WebClient()
Using stream = client.OpenRead("http://www.google.com")
Return True
End Using
End Using
Catch : Return False : End Try
End Function
End Module
Reply
Answers (
2
)
MySql Database backup using c#
Show autogenerated id in textbox in mvc5