Connecting to a SQL Server 2005 Database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?U2hlcndvb2Q=?=

    Connecting to a SQL Server 2005 Database

    Greetings,

    I am using Visual C#.NET 2005 (Express Edition) and want to connect to a SQL
    Server 2005 (Express Edition) database. When I attempt to compile the code
    below, however, I receive the error message:

    "Use of unassigned local variable 'con'"

    System.Data.Sql Client.SqlConne ction con;
    con.ConnectionS tring = "Data Source=HOME-PC\\SQLEXPRESS; Initial
    Catalog=Contact s;User ID=sa";
    con.Open();

    Any ideas as to what I am doing wrong?

    Thanks in advance!
  • =?UTF-8?B?QXJuZSBWYWpow7hq?=

    #2
    Re: Connecting to a SQL Server 2005 Database

    Sherwood wrote:
    I am using Visual C#.NET 2005 (Express Edition) and want to connect to a SQL
    Server 2005 (Express Edition) database. When I attempt to compile the code
    below, however, I receive the error message:
    >
    "Use of unassigned local variable 'con'"
    >
    System.Data.Sql Client.SqlConne ction con;
    con.ConnectionS tring = "Data Source=HOME-PC\\SQLEXPRESS; Initial
    Catalog=Contact s;User ID=sa";
    con.Open();
    >
    Any ideas as to what I am doing wrong?
    You are missing something like:

    con = new SqlConnection() ;

    Arne

    Comment

    • =?Utf-8?B?TXVkYXNzYXIgSGFzc2Fu?=

      #3
      RE: Connecting to a SQL Server 2005 Database

      Try this

      System.Data.Sql Client.SqlConne ction con;
      con = new System.Data.Sql Client.SqlConne ction();
      con.ConnectionS tring = "Data Source=HOME-PC\\SQLEXPRESS; Initial
      Catalog=Contact s;User ID=sa";
      con.Open();


      --
      Regards,
      Mudassar Hassan
      Software Engineer
      Technical endeavors to Microsoft Dynamics 365, Dynamics CRM, Azure and SharePoint



      "Sherwood" wrote:
      Greetings,
      >
      I am using Visual C#.NET 2005 (Express Edition) and want to connect to a SQL
      Server 2005 (Express Edition) database. When I attempt to compile the code
      below, however, I receive the error message:
      >
      "Use of unassigned local variable 'con'"
      >
      System.Data.Sql Client.SqlConne ction con;
      con.ConnectionS tring = "Data Source=HOME-PC\\SQLEXPRESS; Initial
      Catalog=Contact s;User ID=sa";
      con.Open();
      >
      Any ideas as to what I am doing wrong?
      >
      Thanks in advance!

      Comment

      Working...