PROBLEMA QNDO FAZ A PRIMEIRA CONEXAO COM O BANCO
[Ô]The connection is not open[Ô]
dai clico no OK e ele volta pra onde estava, dai clico no login e ele abre normal, não sei mais o que pode ser....
alguns detalhes:
#instalei o win 7 64
#to usando o vs 2008
#isso deu depois q eu atualizei o npgsql pra versão l2.0.11.93
alguém tem alguma dica pra me passar???
Citação:alguém tem alguma dica pra me passar???
Primeira dica: Poste o código.
Citação:
Dim DocXml As XmlDocument = New XmlDocument
Dim DA As NpgsqlDataAdapter = New NpgsqlDataAdapter(ComandoSQL, conn)
Dim cmdSQL As New NpgsqlCommand(ComandoSQL, conn)
Dim DR As Npgsql.NpgsqlDataReader
[ô]#######################################################
[ô]SE NÃO TIVER O ARQUIVO XML COM A CONFIGURAÇÃO DO BANCO
If IO.File.Exists(CaminhoXml) = False Then
MsgBox([Ô]arquivo não encontrado[Ô] & vbNewLine & [Ô]vai pro form de configuração[Ô])
Me.Enabled = False
frmConfig.Visible = True
End If
[ô]Adiciono no Metodo [ô]LoadXml[ô] do objeto [ô]objXml[ô] o caminho do arquivo no servidor
DocXml.Load(CaminhoXml)
ConexaoPG = [Ô]Server=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(0).InnerText & [Ô];[Ô] _
& [Ô]Port=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(1).InnerText & [Ô];[Ô] _
& [Ô]UserId=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(2).InnerText & [Ô];[Ô] _
& [Ô]Password=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(3).InnerText & [Ô];[Ô] _
& [Ô]Database=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(4).InnerText
[ô]##########################
[ô]PASSA A STRING DE CONEXÃO
conn = New NpgsqlConnection(ConexaoPG)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
[ô]Adiciono no Metodo [ô]LoadXml[ô] do objeto [ô]objXml[ô] o caminho do arquivo no servidor
DocXml.Load(CaminhoXml)
ConexaoPG = [Ô]Server=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(0).InnerText & [Ô];[Ô] _
& [Ô]Port=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(1).InnerText & [Ô];[Ô] _
& [Ô]UserId=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(2).InnerText & [Ô];[Ô] _
& [Ô]Password=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(3).InnerText & [Ô];[Ô] _
& [Ô]Database=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(4).InnerText
Dim DA As NpgsqlDataAdapter = New NpgsqlDataAdapter(ComandoSQL, conn)
Dim cmdSQL As New NpgsqlCommand(ComandoSQL, conn)
Dim DR As Npgsql.NpgsqlDataReader
[ô]##########################
[ô]PASSA A STRING DE CONEXÃO
conn = New NpgsqlConnection(ConexaoPG)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim cmdSQL As New NpgsqlCommand(ComandoSQL, conn)
Aqui por exemplo, as variáveis ComandoSQL e conn, vc está preenchendo elas mais acima?
Citação:
Dim DocXml As XmlDocument = New XmlDocument
[ô]#######################################################
[ô]SE NÃO TIVER O ARQUIVO XML COM A CONFIGURAÇÃO DO BANCO
If IO.File.Exists(CaminhoXml) = False Then
MsgBox([Ô]arquivo não encontrado[Ô] & vbNewLine & [Ô]vai pro form de configuração[Ô])
Me.Enabled = False
frmConfig.Visible = True
End If
[ô]Adiciono no Metodo [ô]LoadXml[ô] do objeto [ô]objXml[ô] o caminho do arquivo no servidor
DocXml.Load(CaminhoXml)
ConexaoPG = [Ô]Server=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(0).InnerText & [Ô];[Ô] _
& [Ô]Port=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(1).InnerText & [Ô];[Ô] _
& [Ô]UserId=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(2).InnerText & [Ô];[Ô] _
& [Ô]Password=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(3).InnerText & [Ô];[Ô] _
& [Ô]Database=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(4).InnerText
Dim DA As NpgsqlDataAdapter = New NpgsqlDataAdapter(ComandoSQL, conn)
Dim cmdSQL As New NpgsqlCommand(ComandoSQL, conn)
Dim DR As Npgsql.NpgsqlDataReader
[ô]##########################
[ô]PASSA A STRING DE CONEXÃO
conn = New NpgsqlConnection(ConexaoPG)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
[ô]##################################################
[ô]TRAZER O REGISTRO COM O LOGIN, SENHA E PERMISSÕES
wTabela = [Ô]sisusu[Ô]
wCampos = [Ô]login,senha, cadcli,cadfon,ctapag,ctarec,outroscad,config[Ô]
wCondicao = [Ô]login=[ô][Ô] & Me.txtLogin.Text.Trim.ToLower & [Ô][ô][Ô]
ComandoSQL = [Ô]SELECT [Ô] & wCampos & [Ô] FROM [Ô] & wTabela & [Ô] WHERE [Ô] & wCondicao
DR = cmdSQL.ExecuteReader()
[ô]###############################################
[ô]VERIFICA SE O USUARIO DIGITADO ESTA CADASTRADO
If DR.HasRows = False Then
MsgBox([Ô]Usuário invalido, verifique[Ô], MsgBoxStyle.Critical, Application.ProductName)
Me.txtLogin.Focus()
Exit Sub
End If
[ô]#####################################
[ô]PASSA DADOS DA TABELA PARA VARIÃVEIS
While DR.Read()
PUlogin = DR.GetValue(0).ToString [ô]login
PUsenha = DR.GetValue(1).ToString [ô]senha
PUcadCli = DR.GetValue(2).ToString [ô]cadcli
PUcadFon = DR.GetValue(3).ToString [ô]cadfon
PUctaPag = DR.GetValue(4).ToString [ô]ctapag
PUctaRec = DR.GetValue(5).ToString [ô]ctareg
PUoutrosCad = DR.GetValue(6).ToString [ô]outroscad
PUconfig = DR.GetValue(7).ToString [ô]config
End While
[ô]###############################################
[ô]TESTAR SE A SENHA ESTA OK E SETA AS PERMISSÕES
If Me.txtSenha.Text.Trim.Equals(PUsenha.Trim) = True Then
Me.Visible = False
frmPrincipal.Visible = True
[ô]FAZ AS PERMISSÕES
[ô]VERIFICAR QUAIS MÓDULOS PODEM ACESSAR
If PUcadCli = [Ô]False[Ô] Then
frmPrincipal.cmdCliente.Enabled = False
frmPrincipal.mnuCliente.Enabled = False
End If
If PUcadFon = [Ô]False[Ô] Then
frmPrincipal.cmdFornec.Enabled = False
frmPrincipal.mnuFornec.Enabled = False
End If
If PUctaPag = [Ô]False[Ô] Then
frmPrincipal.cmdCtPag.Enabled = False
frmPrincipal.mnuCtPag.Enabled = False
End If
If PUctaRec = [Ô]False[Ô] Then
frmPrincipal.cmdCtRec.Enabled = False
frmPrincipal.mnuCtRec.Enabled = False
End If
If PUconfig = [Ô]False[Ô] Then
frmPrincipal.cmdConfig.Enabled = False
frmPrincipal.mnuConfig.Enabled = False
End If
Else
MsgBox([Ô]Senha não conferefe, verifique.[Ô], MsgBoxStyle.Critical, Application.ProductName)
txtSenha.Focus()
End If
Você esta querendo passar os parâmetros antes de abrir a conexao.
Dim DA As NpgsqlDataAdapter = New NpgsqlDataAdapter(ComandoSQL, conn)
Dim cmdSQL As New NpgsqlCommand(ComandoSQL, conn)
Dim DR As Npgsql.NpgsqlDataReader
[ô]##########################
[ô]PASSA A STRING DE CONEXÃO
conn = New NpgsqlConnection(ConexaoPG)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Tente assim
[ô]##########################
[ô]PASSA A STRING DE CONEXÃO
conn = New NpgsqlConnection(ConexaoPG)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim DA As NpgsqlDataAdapter = New NpgsqlDataAdapter(ComandoSQL, conn)
A ordem em que acontece as coisas é fundamental, você não pode executar uma consulta em chamar a conexão, vc esta executando a consulta antes de abrir a conexão e passar a SQL.
Citação:
Dim DocXml As XmlDocument = New XmlDocument
Dim cmdSQL As New NpgsqlCommand()
Dim DA As New NpgsqlDataAdapter
Dim DR As Npgsql.NpgsqlDataReader
[ô]#######################################################
[ô]SE NÃO TIVER O ARQUIVO XML COM A CONFIGURAÇÃO DO BANCO
If IO.File.Exists(CaminhoXml) = False Then
MsgBox([Ô]arquivo não encontrado[Ô] & vbNewLine & [Ô]vai pro form de configuração[Ô])
Me.Enabled = False
frmConfig.Visible = True
End If
[ô]Adiciono no Metodo [ô]LoadXml[ô] do objeto [ô]objXml[ô] o caminho do arquivo no servidor
DocXml.Load(CaminhoXml)
ConexaoPG = [Ô]Server=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(0).InnerText & [Ô];[Ô] _
& [Ô]Port=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(1).InnerText & [Ô];[Ô] _
& [Ô]UserId=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(2).InnerText & [Ô];[Ô] _
& [Ô]Password=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(3).InnerText & [Ô];[Ô] _
& [Ô]Database=[Ô] & DocXml.SelectSingleNode([Ô]BANCO[Ô]).ChildNodes(4).InnerText
[ô]##########################
[ô]PASSA A STRING DE CONEXÃO
conn = New NpgsqlConnection(ConexaoPG)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
[ô]##################################################
[ô]TRAZER O REGISTRO COM O LOGIN, SENHA E PERMISSÕES
wTabela = [Ô]sisusu[Ô]
wCampos = [Ô]login,senha, cadcli,cadfon,ctapag,ctarec,outroscad,config[Ô]
wCondicao = [Ô]login=[ô][Ô] & Me.txtLogin.Text.Trim.ToLower & [Ô][ô][Ô]
ComandoSQL = [Ô]SELECT [Ô] & wCampos & [Ô] FROM [Ô] & wTabela & [Ô] WHERE [Ô] & wCondicao
cmdSQL = New NpgsqlCommand(ComandoSQL, conn)
DR = cmdSQL.ExecuteReader()
DA = New NpgsqlDataAdapter(ComandoSQL, conn)
[ô]###############################################
[ô]VERIFICA SE O USUARIO DIGITADO ESTA CADASTRADO
If DR.HasRows = False Then
MsgBox([Ô]Usuário invalido, verifique[Ô], MsgBoxStyle.Critical, Application.ProductName)
Me.txtLogin.Focus()
Exit Sub
End If
[ô]#####################################
[ô]PASSA DADOS DA TABELA PARA VARIÃVEIS
While DR.Read()
PUlogin = DR.GetValue(0).ToString [ô]login
PUsenha = DR.GetValue(1).ToString [ô]senha
PUcadCli = DR.GetValue(2).ToString [ô]cadcli
PUcadFon = DR.GetValue(3).ToString [ô]cadfon
PUctaPag = DR.GetValue(4).ToString [ô]ctapag
PUctaRec = DR.GetValue(5).ToString [ô]ctareg
PUoutrosCad = DR.GetValue(6).ToString [ô]outroscad
PUconfig = DR.GetValue(7).ToString [ô]config
End While
[ô]###############################################
[ô]TESTAR SE A SENHA ESTA OK E SETA AS PERMISSÕES
If Me.txtSenha.Text.Trim.Equals(PUsenha.Trim) = True Then
Me.Visible = False
frmPrincipal.Visible = True
[ô]FAZ AS PERMISSÕES
[ô]VERIFICAR QUAIS MÓDULOS PODEM ACESSAR
If PUcadCli = [Ô]False[Ô] Then
frmPrincipal.cmdCliente.Enabled = False
frmPrincipal.mnuCliente.Enabled = False
End If
If PUcadFon = [Ô]False[Ô] Then
frmPrincipal.cmdFornec.Enabled = False
frmPrincipal.mnuFornec.Enabled = False
End If
If PUctaPag = [Ô]False[Ô] Then
frmPrincipal.cmdCtPag.Enabled = False
frmPrincipal.mnuCtPag.Enabled = False
End If
If PUctaRec = [Ô]False[Ô] Then
frmPrincipal.cmdCtRec.Enabled = False
frmPrincipal.mnuCtRec.Enabled = False
End If
If PUconfig = [Ô]False[Ô] Then
frmPrincipal.cmdConfig.Enabled = False
frmPrincipal.mnuConfig.Enabled = False
End If
Else
MsgBox([Ô]Senha não conferefe, verifique.[Ô], MsgBoxStyle.Critical, Application.ProductName)
txtSenha.Focus()
End If