How do I connect a sql database to an html site using asp?
Note: I already have the whole bank developed and the whole page too, I just need to know how I bridge the two
How do I connect a sql database to an html site using asp?
Note: I already have the whole bank developed and the whole page too, I just need to know how I bridge the two
Gui Sartori, it's good to put some details that make the difference type:
If asp classico follows
'<%
Dim conexao, stringConexao, host, usuario, senha, banco
host ="SERVIDOR"
usuario="BASE"
senha ="SENHA"
banco ="BANCO"
Monta a string de conexão utilizando os dados informados anteriormente
stringConexao ="Provider=SQLNCLI10;
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
%>
I do not know asp classico I saw this code in the wiki of the locaweb go here
There are several ways to solve your problem. I would use the entity framework to map my database objects to classes (database-first) and insert my conectionstring into the config. After that, in your controller (if it is MVC), refer to the database connection and execute the necessary query by saving the results in a < > list. Send the controller list to view via viewmodel ..
Ex. controller: private ProductsContext bancodedados = new ProductsContext ();
List products = new List products = banked.Products.ToList ();
* You need to create a Products class () with its properties, example: ProductID, Name, Description, Price {get; set;} etc ..
p>I recommend you read these two articles.