Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. Imports System.Data.OleDb
  2. Imports System.Data.SqlClient
  3. Imports MySql.Data.MySqlClient
  4. Imports Npgsql
  5.  
  6. Module Connection
  7. Dim db_string As String
  8. Dim Conn1 As OleDbConnection '' Access DB
  9. Dim Conn2 As SqlConnection '' Ms SQL Server
  10. Dim Conn3 As MySqlConnection '' Mysql
  11. Dim Conn4 As NpgsqlConnection '' PostgreSQL
  12.  
  13. Sub DBConn_Accdb() '' Connection For Access DB
  14. db_string = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Net\tarman.accdb;"
  15. Conn1 = New OleDbConnection(db_string)
  16.  
  17. Try
  18. Conn1.Open()
  19. MsgBox("DB Access Success")
  20. Catch ex As OleDbException
  21. MsgBox(ex.Message)
  22. End Try
  23. End Sub
  24.  
  25. Sub DBConn_MsSQL() ''COnnection For Ms SQL Server
  26. db_string = "Data Source=WJT-01\SQLEXPRESS;Initial Catalog=customer;User ID=sa;Password=12345;"
  27. Conn2 = New SqlConnection(db_string)
  28.  
  29. Try
  30. Conn2.Open()
  31. MsgBox("Ms SQL Server Success")
  32. Catch ex As SqlException
  33. MsgBox(ex.Message)
  34. End Try
  35.  
  36. End Sub
  37.  
  38. Sub DBConn_MySQL()
  39. db_string = "server=localhost;user=root;password=wishimajaya;port=3307;database=ma star;"
  40. Conn3 = New MySqlConnection(db_string)
  41. Try
  42. Conn3.Open()
  43. MsgBox("MySQL Success")
  44. Catch ex As MySqlException
  45. MsgBox(ex.Message)
  46. End Try
  47. End Sub
  48.  
  49. Sub DBConn_PgSQL()
  50. db_string = "Server=localhost;Port=5432;Database=customer;username=postgres;password=wishimajaya"
  51. Conn4 = New NpgsqlConnection(db_string)
  52.  
  53. Try
  54. Conn4.Open()
  55. MsgBox("PostgreSQL Succes")
  56. Catch ex As NpgsqlException
  57. MsgBox(ex.Message)
  58. End Try
  59. End Sub
  60. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement