PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 20, 2022

[FIXED] How to test if a connection to a Db is established successfully?

 April 20, 2022     .net, ado.net, c#, connection, unit-testing     No comments   

Issue

I want to write a unit-test which asserts a connection string is valid so that a conenction is established to a SQL Db.

if I have :

string connectionString = GetCOnenctionString();
bool conenctionEstablished = false;

How can I set 'conenctionEstablished' variable's value as a result of a check to a Db with the 'connectionString' provided?

So that I can use it in an Assert.


Solution

You could try to connect in a try/catch then set conenctionEstablished based on whether the connection succeeds or not.



Answered By - sproketboy
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing