Abaixo exemplos simples de como conectar-se a um banco de dados Microsoft SQL Server através de scripts Asp:
Windows 2012
No ambiente Windows 2012 os drivers instalados para este tipo de conexão são: SQLNCLI10 e SQLNCLI1. Segue exemplo:
<% '##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 ="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 %>
Windows 2008
No ambiente Windows 2008 o driver instalado para este tipo de conexão é o: SQLNCLI10, por este motivo, segue exemplo utilizando o mesmo:
<% '##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 ="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 %>
Windows 2005
Arquivo: mssql.asp
<% '##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 %>
Os códigos acima são somente exemplos. Caso haja dúvidas quanto sua utilização, sugerimos que verifique juntamente a um desenvolvedor de sua confiança.
Veja também
Uczyniłeś złożoną temat dostępną Świetną pracę|To nagraj to klejnot Więc zadowolony jak poncz konfigurowałem to|Ty ojciec zdumiewające zdolność do pisania atrakcyjna treść|To pismo na najwyższym poziomie zdobyłeś fresh obserwującego|Twój post był zarówno wnikliwy, jak i uroczo napisany|Jestem zdumiony poza jak wiele nauczyłem się z tego posta|wykonujesz adept pracę To wysłanie jest zeznanie o tym} {https://kredytero.pl|kredytero.pl|kredyt|kredyty|kredyt online|kredyty online|kredyt przez internet|kredyty przez internet}!
I’m amazed past how much I learned from this post play bitcoin gambling online.
You be enduring a gift for explaining complex topics easily play with bonuses on online sports betting sites.
I’m in awe of your talent with a view writing This was brilliant online sports betting.
You’re doing notable work This dispatch is proof of that online gambling.
You nailed it with this post Exceedingly helpful Sports Betting Bonuses.
This send is a gem So glad I bring about it casinos.
Your cleverness to captivate readers is remarkable Gigantic post play casino games real money.
Amazing post You covered this thesis perfectly onlinecasinogit.com/.
I’m in awe of your knack with a view writing This was brilliant.
Your insights are invaluable Actually appreciate your work.
First-class post I’m obviously sharing this with my friends.
I’m amazed past how much I cultured from this post
You’ve made a complex thesis accessible Great job installmentloanskov.com/.
I’m blown away near your learning and handwriting style
Loved every dispatch of this You’re a frankly expert
I’m thoroughly impressed by your latest blog post. The way you’ve articulated your points is nothing short of brilliant. Your balanced approach, blending in-depth research with personal anecdotes, makes your writing not only informative but also highly relatable bshnwmrih.wordpress.com/.
I really appreciate this post. I have been looking all over for this! Thank goodness I found it on Bing. You have made my day! Thanks again
Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your weblog? My blog is in the exact same area of interest as yours and my users would genuinely benefit from a lot of the information you present here. Please let me know if this okay with you. Many thanks!
Hello! Quick question that’s completely off topic. Do you know how to make your site mobile friendly? My weblog looks weird when viewing from my apple iphone. I’m trying to find a template or plugin that might be able to resolve this issue. If you have any suggestions, please share. With thanks!
We’re a gaggle of volunteers and starting a new scheme in our community. Your site provided us with valuable information to work on. You have performed a formidable job and our whole community will probably be thankful to you.
We are a bunch of volunteers and opening a new scheme in our community. Your site provided us with valuable information to paintings on. You have done a formidable task and our entire community might be thankful to you.
That is the right blog for anybody who wants to search out out about this topic. You realize so much its nearly arduous to argue with you (not that I actually would need…HaHa). You positively put a brand new spin on a subject thats been written about for years. Nice stuff, simply nice!
I was suggested this blog by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my difficulty. You are amazing! Thanks!
magnificent points altogether, you just gained a new reader. What would you suggest in regards to your post that you made a few days ago? Any positive?
You completed a number of nice points there. I did a search on the issue and found nearly all people will have the same opinion with your blog.betflik
WONDERFUL Post.thanks for share..extra wait .. …
I found your blog site on google and check a few of your early posts. Continue to maintain up the superb operate. I just extra up your RSS feed to my MSN News Reader. Looking for ahead to studying more from you later on!…
Amazing blog! Is your theme custom made or did you download it from somewhere? A design like yours with a few simple tweeks would really make my blog stand out. Please let me know where you got your design. Many thanks
Wow! This can be one particular of the most helpful blogs We have ever arrive across on this subject. Actually Great. I am also an expert in this topic therefore I can understand your hard work.
As I website possessor I believe the content matter here is rattling magnificent , appreciate it for your efforts. You should keep it up forever! Best of luck.
You completed a number of nice points there. I did a search on the issue and found nearly all people will have the same opinion with your blog.betflik
Fantastic post but I was wanting to know if you could write a litte more on this topic? I’d be very grateful if you could elaborate a little bit more. Thanks!