[VB]資料庫連線測試

必須先加入參考

sql連線
  Using cn As New SqlConnection("Data Source=local;Initial Catalog=SMAC;Persist Security Info=True;User ID=sa;Password=pad")
            cn.Open()
            Using cmd As New SqlCommand("", cn)

                If cn.State = ConnectionState.Open Then '連線開啟
                    MessageBox.Show("OP")
                Else
                    MessageBox.Show("CL")
                End If

            End Using
        End Using


pg連線
        Using cn As New NpgsqlConnection("Server=local;Port=5432;Database=SMAC;Userid=postgres;Password=pad; Protocol=3;SSL=false;Pooling=true;MinPoolSize=1;MaxPoolSize=20;Encoding=UNICODE;Timeout=15;CommandTimeout=600;SslMode=Disable;")
            cn.Open()
            Using cmd As New NpgsqlCommand("", cn)

                If cn.State = ConnectionState.Open Then '連線開啟
                    MessageBox.Show("OP")
                Else
                    MessageBox.Show("CL")
                End If

            End Using
        End Using