Solved

Test a SQL String Connection.

Posted on 2011-09-09
6
323 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
  • 3
  • 2
6 Comments
 
LVL 5

Assisted Solution

by:zvytas
zvytas earned 100 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 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 400 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 400 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now