0

I am developing an application in Classic ASP
My database is SQLSErver 2008

I am getting a problem in connecting to my database.

Here is the code which i used to connect.

connstring ="server=mymsever;database=mydb;Trusted_Connection=Yes;"
 set conntemp = server.createobject("ADODB.Connection")
 conntemp.ConnectionString=connstring
 conntemp.Open()
 Response.Write(conntemp.State)

The last statement is for the confirmation that is my connection status open or not. But each time i get 0 as printed which means its closed.

What to do in this case. How to connect it.

3
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by Golden-Boy
0
'##Declara as variaveis a serem utilizadas no script
Dim conexao, stringConexao, host, usuario, senha, banco

'##Informe os dados de conexão junto ao banco Microsoft SQL Server
host   ="ENDERECO_SQL_SERVER"
usuario="USUARIO" 
senha  ="SENHA"
banco  ="BANCO"

'##Monta a string de conexão utilizando os dados informados anteriormente
stringConexao = "Provider=SQLOLEDB.1;SERVER="&host&";DATABASE="&banco&";UID="&usuario&";PWD="&senha&";"

'##Instancia o objeto de conexão com o banco
SET conexao = Server.CreateObject("ADODB.Connection")

On Error Resume Next

'##Abre a conexão junto ao banco
conexao.Open stringConexao

'##Tratamento de erro. Caso ocorra problemas na conexão, exibe esta informação e apresenta detalhes.
If Err.Number <> 0 Then
    response.write "<b><font color='red'> Conexão com o banco '" & banco & "' Microsoft SQL Server falhou !</font></b>"
    response.write "<BR><BR>"
    response.write "<b>Erro.Description:</b> " & Err.Description & "<br>"
    response.write "<b>Erro.Number:</b> " & Err.Number & "<br>"
    response.write "<b>Erro.Source:</b> " & Err.Source & "<br>"
Else
   '##Caso a conexão seja bem sucedida, mostra mensagem de confirmação.
   response.write "<b><font color='blue'> Conexão com o banco '" & banco & "' Microsoft SQL Server estabelecida com sucesso !</font>"
End If

'##Fecha a conexão com o banco
conexao.close

'##Remove as referência do objeto da memória
SET conexao = Nothing

Edited by pritaeas: Removed fake sig.

0

Try this and see

connstring ="provider=sqloledb;data source=[B]YOURSERVER[/B];initial catalog=[B]DATABASENAME[/B];user id=[B]USERNAME[/B];password=[B]PASSWORD[/B];"
 set conntemp = server.createobject("ADODB.Connection")
 conntemp.ConnectionString=connstring
 conntemp.Open()
 Response.Write(conntemp.State)

Edited by Golden-Boy: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.