?
Solved

Test a SQL String Connection.

Posted on 2011-09-09
6
Medium Priority
?
344 Views
Last Modified: 2012-05-12
I have a SQL Server2005 studio express  mangement Express and i have this line code in my visual studio.

how i'm able to test it in my SQL if the connection work to my database.  Please details step by step how i can test my db connection ?

here is my vstudio code  

string myConnectionString = "server=SCCAPP1;database=abc_WEB;User ID=abc;password=abcd";
0
Comment
Question by:LelloLello
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Assisted Solution

by:zvytas
zvytas earned 400 total points
ID: 36511713
string myConnectionString = "server=SCCAPP1;database=abc_WEB;User ID=abc;password=abcd";
SqlConnection myConnection = new SqlConnection(myConnectionString)
try
{
  myConnection.Open();
  // connection successful
}
catch
{
  // connection failed
}
finally
{
  if (myConnection.State == ConnectionState.Open)
  {
    myConnection.Close();
  }
}
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1600 total points
ID: 36511719
Create a throw-away project and do something like the following:

C#
try
{
    System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(myConnectionString);

    con.Open();
    con.Close();
    con.Dispose();
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
    // or if you're using a forms app
    MessageBox.Show(ex.ToString());
}

Open in new window


If you see the message, then the connection failed. You should get an indication as to why from the message printed.
0
 

Author Comment

by:LelloLello
ID: 36511814
Well i'd like to test it in my microsoft SQL Studio ? could you please advice.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1600 total points
ID: 36512086
If you are referring to SQL Server Management Studio (SSMS), then you can simply enter the appropriate details on the "Connect to Server" window (File->Connect Object Explorer).

Screenshot
Once you connect, if you cannot see the "Object Explorer," you can open by going to View->Object Explorer or by pressing the F8 key.
0
 

Author Comment

by:LelloLello
ID: 36512459
okay i'm there but i wasn't able to find that DB ? where i should look for a database=abc_WEB
0
 

Author Comment

by:LelloLello
ID: 36512460
i've logged in.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question