Muitos programadores utilizam include para abrir a conexão com o banco de dados, porém o ODP apresenta erro dizendo que a conexão não foi fechada e o objeto não foi destruido, mesmo fechando a conexão e destruindo o objeto no final do arquivo onde está o include.

Criando função para abri conexão

Nesses casos devemos criar uma função para abrir a conexão passando os parâmetros da mesma e uma sub para fechá-la, como o exemplo abaixo (vamos chamá-lo de db.asp):

 <% function abre_conexao(ConnString,conexao) ConnString="Provider=SQLOLEDB.1;SERVER=HM87;DATABASE=nomedabase;UID=login;PWD=senha;" set conexao=server.createobject("adodb.connection") conexao.open ConnString end function   sub fecha_conexao() conexao.close set conexao = nothing end sub %> 

Na página onde será feita a conexão, coloque o include:

 <!--#INCLUDE file="db.asp" -->  

Para abrir a conexão basta chamar a sub:

 Call abre_conexao(ConnString,conexao) 

e para fechá-la chamar a sub:

 Call fecha_conexao()  

OBS: O código de programação mencionado neste artigo é uma sugestão. Contamos com sua compreensão para o fato de que a Locaweb não pode se responsabilizar por apresentar mais detalhes a respeito de sua implementação e utilização. Para mais informações, sugerimos que entre em contato com o seu desenvolvedor, pois tal conhecimento é aberto e de domínio de profissionais técnicos. Caso queira entrar em contato conosco a respeito deste tema, orientamos a abrir um chamado via HelpDesk.

Veja também


SQL Server

SQL Server Native Client 10.0 OLE DB Provider

Segurança Padrão

 Provider=SQLNCLI10;Server=EnderecoDoServidor;Database=NomeDaBaseDeDados;Uid=UsuarioSQL; Pwd=SenhaSQL; 

Database mirroring

Se sua aplicação acessa uma base de dados via ADO.NET ou SQL Native Client, você pode configurar para que o driver redirecione a conexão para o servidor com a base de dados Principal automaticamente em caso de failover. Você precisa informar o servidor principal e o servidor parceiro na string de conexão:

 Provider=SQLNCLI10;Data Source=EnderecoDoServidor;Failover Partner=EnderecoDoServidorMirror; Initial Catalog=NomeDaBaseDeDados;User Id=UsuarioSQL;Password=SenhaSQL; 

SQL Server Native Client 10.0 ODBC Driver

Segurança Padrão

 Driver={SQL Server Native Client 10.0};Server=EnderecoDoServidor;Database=NomeDaBaseDeDados; Uid=UsuarioSQL;Pwd=SenhaSQL; 

Database mirroring

Se sua aplicação acessa uma base de dados via ADO.NET ou SQL Native Client, você pode configurar para que o driver redirecione a conexão para o servidor com a base de dados Principal automaticamente em caso de failover. Você precisa informar o servidor principal e o servidor parceiro na string de conexão:

 Driver={SQL Server Native Client 10.0};Server=EnderecoDoServidor;Database=NomeDaBaseDeDados; Failover_Partner=EnderecoDoServidorMirror;Uid=UsuarioSQL;Pwd=SenhaSQL; 

SQL Native Client 9.0 OLE DB provider

Segurança Padrão

 Provider=SQLNCLI;Server=EnderecoDoServidor;Database=NomeDaBaseDeDados; Uid=UsuarioSQL; Pwd=SenhaSQL; 

Database mirroring

Se sua aplicação acessa uma base de dados via ADO.NET ou SQL Native Client, você pode configurar para que o driver redirecione a conexão para o servidor com a base de dados Principal automaticamente em caso de failover. Você precisa informar o servidor principal e o servidor parceiro na string de conexão:

 Provider=SQLNCLI;Data Source=EnderecoDoServidor;Initial Catalog=NomeDaBaseDeDados; Failover Partner=EnderecoDoServidorMirror;User Id=UsuarioSQL;Password=SenhaSQL; 

SQL Native Client 9.0 ODBC Driver

Segurança Padrão

 Driver={SQL Server Native Client};Server=EnderecoDoServidor;Database=NomeDaBaseDeDados; Uid=UsuarioSQL;Pwd=SenhaSQL; 

Database mirroring

Se sua aplicação acessa uma base de dados via ADO.NET ou SQL Native Client, você pode configurar para que o driver redirecione a conexão para o servidor com a base de dados Principal automaticamente em caso de failover. Você precisa informar o servidor principal e o servidor parceiro na string de conexão:

 Driver={SQL Server Native Client};Server=EnderecoDoServidor;Database=NomeDaBaseDeDados; Failover_Partner=EnderecoDoServidorMirror;Uid=UsuarioSQL;Pwd=SenhaSQL; 

.NET Framework Data Provider for SQL Server

Segurança Padrão

 Data Source=EnderecoDoServidor;Initial Catalog=NomeDaBaseDeDados;User Id=UsuarioSQL;Password=SenhaSQL; 

Database mirroring

Se sua aplicação acessa uma base de dados via ADO.NET ou SQL Native Client, você pode configurar para que o driver redirecione a conexão para o servidor com a base de dados Principal automaticamente em caso de failover. Você precisa informar o servidor principal e o servidor parceiro na string de conexão:

 Data Source=EnderecoDoServidor;Initial Catalog=NomeDaBaseDeDados; Failover Partner=EnderecoDoServidorMirror;User Id=UsuarioSQL;Password=SenhaSQL; 

Microsoft SQL Server OLE DB Provider

Segurança Padrão

 Provider=sqloledb;Data Source=EnderecoDoServidor;Initial Catalog=NomeDaBaseDeDados; User Id=UsuarioSQL;Password=SenhaSQL; 

Microsoft SQL Server ODBC Driver

Segurança Padrão

 Driver={SQL Server};Server=EnderecoDoServidor;Initial Catalog=NomeDaBaseDeDados; User Id=UsuarioSQL;Password=SenhaSQL; 

MySQL

MySQL Connector/ODBC 5.1

Segurança Padrão

 Driver={MySQL ODBC 5.1 Driver};Server=EnderecoDoServidor;Port=3306;Database=NomeDaBaseDeDados; User=UsuarioSQL; Password=SenhaSQL;Option=3; 

MySQL Connector/Net

Segurança Padrão

 Server=EnderecoDoServidor;Database=NomeDaBaseDeDados;Uid=UsuarioMySQL;Pwd=SenhaMySQL;Port=3306; 

PostgreSQL

PostgreSQL ANSI

 Driver={PostgreSQL ANSI};Server=EnderecoDoServidor;Port=5432;Database=NomeDaBaseDeDados;Uid=UsuarioSQL;Pwd=SenhaSQL; 

PostgreSQL UNICODE

 Driver={PostgreSQL UNICODE};Server=EnderecoDoServidor;Port=5432;Database=NomeDaBaseDeDados;Uid=UsuarioSQL;Pwd=SenhaSQL; 

Referências

Oracle

Oracle Provider for OLE DB

TNS-less connection string

 Provider=OraOLEDB.Oracle.1;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP) (HOST=EnderecoDoServidor)(PORT=PortaDoServidor)))(CONNECT_DATA=(SID=SIDdoOracle)(SERVER=DEDICATED))); User Id=UsuarioOracle;Password=SenhaOracle; 

MS Access

ACE OLEDB 12.0

Segurança Padrão

 Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:/home/LOGIN_DE_FTP/dados/bancoAccess.accdb; Persist Security Info=False; 

ACE OLEDB 12.0

Utilizando Senha

 Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:/home/LOGIN_DE_FTP/dados/bancoAccess.accdb; Jet OLEDB:NOME_DO_BANCO Password=SENHA_DO_BANCO; 

Microsoft Jet OLE DB 4.0

Segurança Padrão

 Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:/home/LOGIN_DE_FTP/dados/bancoAccess.mdb; 

Veja também


Esse artigo ajudou você?

44 respostas para “Como utilizar includes para abrir e fechar conexões com bancos”

  1. Skincell Pro website

    I was able to find good info from your blog articles.

    Responder
  2. Cannabis Seed Mixpacks Delivery

    Having read this I believed it was really enlightening. I appreciate you finding the time and energy to put this short article together. I once again find myself personally spending way too much time both reading and commenting. But so what, it was still worthwhile.

    Responder
  3. white corset lingerie

    Good – I should certainly pronounce, impressed with your website. I had no trouble navigating through all tabs and related information ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or something, web site theme . a tones way for your customer to communicate. Nice task.

    Responder
  4. sex gift

    Hello there! This post could not be written any better! Reading through this post reminds me of my previous room mate! He always kept chatting about this. I will forward this article to him. Pretty sure he will have a good read. Thank you for sharing!

    Responder
  5. Oliva Rady

    Having read this I believed it was really informative. I appreciate you taking the time and energy to put Taruhan Bola Untung this information together. I once again find myself personally spending a significant amount of time both reading and commenting

    Responder
  6. free horror

    That is a good tip especially to those fresh to the blogosphere. Simple but very accurate info… Appreciate your sharing this one. A must read article!

    Responder
  7. shoes

    Greetings! Very useful advice in this particular post! It’s the little changes that produce the largest changes. Thanks for sharing!

    Responder
  8. Augustus Delauder

    There are a handful of intriguing points at some point here but I do not know if I see they all center to heart. There exists some validity but I most certainly will take hold opinion until I take a look at it further. Good article , thanks and now we want more! Put into FeedBurner in addition

    Responder
  9. Shoshana Tritz

    How can I contact you? I am interested in more info. I love sucking dick btw hmu

    Responder
  10. Noel Filbrardt

    The article is worth reading, I like it very much. I will keep your new articles.

    Responder
  11. Pretty Gaming

    Oh my goodness! Impressive article dude! Many thanks, However I am experiencing issues with your RSS. I don’t understand the reason why I cannot join it. Is there anybody else having identical RSS issues? Anyone that knows the answer can you kindly respond? Thanks!!

    Responder
  12. Edwin Giallorenzo

    Hello there, just became aware of your blog through Google, and found that it’s really informative. I will appreciate if you continue this in future. Numerous people will benefit from your writing. Cheers!

    Responder
  13. White glove service

    I like this post, enjoyed this one regards for putting up. “The world is round and the place which may seem like the end may also be only the beginning.” by George Baker.

    Responder
  14. Humberto Willier

    The digital cigarette makes use of a battery and a small heating element the vaporize the e-liquid. This vapor can then be inhaled and exhaled

    Responder
  15. Leslie Bofinger

    […]The next few web sites happen to be some web-sites that fascinated our administrator, and so make sure you have a look at all of them[…]

    Responder
  16. what is medicare medical insurance

    I simply want to input that you have ? good website ?nd I enjoy the design and also artcles
    ?n it!

    Responder
  17. Nimbus Unicycles Unicycles for sale

    Wow! This could be one particular of the most helpful blogs We have ever arrive across on this subject. Actually Excellent. I am also a specialist in this topic therefore I can understand your hard work.

    Responder
  18. Read More Here

    I just want to mention I’m new to weblog and honestly savored your web-site. Probably I’m going to bookmark your site . You definitely come with awesome stories. Kudos for revealing your blog site.

    Responder
  19. Plumbing Services San Diego click here to investigate

    you are really a good webmaster. The website loading speed is amazing. It seems that you’re doing any unique trick. In addition, The contents are masterpiece. you have done a excellent job on this topic!

    Responder
  20. home warranty service

    Yoou need to take part in a contest for one oof the
    most useful websites online. I wil recommnd this site!

    Responder
  21. vehicle donation

    Very good post! We will be linking to this great content on our website.Keep up
    tthe great writing!

    Responder
  22. slot games

    Best view i have ever seen !

    Responder
  23. 마사지구인구직

    Your blog is great as in the event it were being written by means of a writer. I am going to take a look at your blog frequently. Thank you always.

    Responder
  24. structural repair contractors

    In this grand scheme of things you actually receive an A+ for effort. Exactly where you confused everybody ended up being on all the details. You know, it is said, the devil is in the details… And that could not be more true in this article. Having said that, permit me say to you what did work. The writing is definitely highly engaging and that is most likely why I am taking the effort to opine. I do not make it a regular habit of doing that. Second, although I can certainly see the jumps in reason you make, I am not necessarily sure of exactly how you appear to connect the details which in turn produce your conclusion. For right now I will subscribe to your issue however wish in the foreseeable future you actually link your facts much better.

    Responder
  25. VitalFlow supplement

    Howdy, I do think your website may be having browser compatibility problems. When I look at your website in Safari, it looks fine however, when opening in I.E., it’s got some overlapping issues. I simply wanted to give you a quick heads up! Aside from that, wonderful blog.

    Responder
  26. Home Protection Plans

    Wow, amazing blog layout! How long have you been blogging for?
    you made blogging look easy. The overall loook
    of your web siye is excellent,as well as the content.

    Responder
  27. White glove delivery

    I have to show some thanks to you for rescuing me from this particular setting. After checking through the the net and coming across tricks which were not productive, I believed my entire life was gone. Being alive minus the solutions to the problems you’ve solved through your entire article is a crucial case, and the kind that might have badly affected my career if I hadn’t discovered your site. Your primary expertise and kindness in dealing with every part was useful. I am not sure what I would have done if I had not discovered such a step like this. I’m able to at this moment look ahead to my future. Thanks a lot so much for your skilled and effective guide. I will not think twice to suggest your web page to any person who would like guidance on this issue.

    Responder
  28. living room refurbishment

    Your home is valueble for me. Thanks!…

    Responder
  29. Pool table movers

    You actually make it seem so easy with your presentation but I find this matter to be actually something that I think I would never understand. It seems too complex and very broad for me. I am looking forward for your next post, I will try to get the hang of it!

    Responder
  30. White glove furniture delivery

    One other important aspect is that if you are a senior citizen, travel insurance for pensioners is something you ought to really take into account. The old you are, the harder at risk you will be for allowing something bad happen to you while abroad. If you are not covered by quite a few comprehensive insurance cover, you could have a number of serious complications. Thanks for discussing your advice on this blog site.

    Responder
  31. for house renovation

    Hello, i think that i saw you visited my web site thus i came to “go back the favor”.I’m attempting to in finding things to enhance my website!I suppose its ok to use some of your ideas!!

    Responder
  32. digital marketing level 8

    Hi there! Do you use Twitter? I’d like to follow you if that would be ok. I’m definitely enjoying your blog and look forward to new updates.

    Responder
  33. sites

    I simply want to tell you that I am just new to weblog and truly loved this website. More than likely I’m planning to bookmark your blog . You amazingly come with awesome article content. Appreciate it for sharing with us your blog.

    Responder
  34. roadside assistance

    Hello! Do you use Twitter? I’d like to follow you if that would be ok. I’m absolutely enjoying your blog and look forward to new posts.

    Responder
  35. alberta car towing

    It¡¦s actually a great and useful piece of information. I am satisfied that you simply shared this useful info with us. Please keep us informed like this. Thank you for sharing.

    Responder
  36. Maryland pool table movers

    Wow! Thank you! I always wanted to write on my website something like that. Can I take a portion of your post to my blog?

    Responder
  37. this post

    Some really fantastic articles on this website, appreciate it for contribution. “An alcoholic is someone you don’t like who drinks as much as you do.” by Dylan Thomas.

    Responder
  38. look at here now

    What’s Happening i am new to this, I stumbled upon this I’ve found It absolutely useful and it has aided me out loads. I hope to contribute & aid other users like its aided me. Great job.

    Responder
  39. Jaime Grimaldi

    I just want to mention I am newbie to weblog and definitely liked your blog. Most likely I’m planning to bookmark your blog . You amazingly have really good articles and reviews. Cheers for sharing with us your website page.

    Responder

Comente sobre este conteúdo! Escreva o que pensa, complemente, vamos discutir. O conhecimento é livre!