954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Connection of Sqlserver2008 with classic asp

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.

MARKAND911
Junior Poster
126 posts since Nov 2008
Reputation Points: 10
Solved Threads: 2
 

'##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 " Conexão com o banco '" & banco & "' Microsoft SQL Server falhou !"
response.write "

"
response.write "Erro.Description: " & Err.Description & "
"
response.write "Erro.Number: " & Err.Number & "
"
response.write "Erro.Source: " & Err.Source & "
"
Else
'##Caso a conexão seja bem sucedida, mostra mensagem de confirmação.
response.write " Conexão com o banco '" & banco & "' Microsoft SQL Server estabelecida com sucesso !"
End If

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

'##Remove as referência do objeto da memória
SET conexao = Nothing
---------------------------------------------
Wilbor
================
www.wilsites.net

wilsites
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Try this and see

connstring ="provider=sqloledb;data source=<strong>YOURSERVER</strong>;initial catalog=<strong>DATABASENAME</strong>;user id=<strong>USERNAME</strong>;password=<strong>PASSWORD</strong>;"
 set conntemp = server.createobject("ADODB.Connection")
 conntemp.ConnectionString=connstring
 conntemp.Open()
 Response.Write(conntemp.State)
Golden-Boy
Newbie Poster
5 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: