C#.NET2008 SQL SERVER Connection string CLASS

Reply Forum
Forum postLennie @ 2010-03-30 06:25:47
ReplyReply to
Hi Good Guys, :lol:

I have problem using C#.Net2008. I have created CLASSConnectionString and using FrmDataGrid to instantiate it to retrieve the SQL SERVER Connection string from it. Among the coding I placed <-- Error to denounce the cause of problem.:

This is the first time that I have created a CLASS like VB.NET2008 to ensure all the programs within the same Project can retrieve SQLSERVER connection string. In VBNET2008 it works very well but C#.NET2008 I am struggling with it because I am new to C#.NET2008.

The name of my SQL SERVER is KUAHFAMILY\LOCALHOST
Please Help me. I need your help.

Here are the CLASS Coding and FRMDATAGRID coding.
--------------------------------------------------------

// ClassConnectionString coding

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;

namespace ClassConnectionString
{
  public class ClassConn
   {
     /*  sql server name is KUAHFAMILY\LOCALHOST      
         declare variables, */         

       public string clsGvConnstr = "";

     public String PropSQLSRVconnection()
       { 
          clsGvConnstr += "Integrated Security=SSPI";
          clsGvConnstr += "Data Source = KuahFamily\LocalHost"; <-- Error \LocalHost 
          clsGvConnstr += "Persist Security Info=False";
          clsGvConnstr += "Initial Catalog = NorthWind";

          string PropAdoconnection = clsGvConnstr;
          return PropAdoconnection;
       }
     }
}



--------------------------------------------------
// FORM FrmDataGrid.CS coding

 using System.Data.SqlClient;
using System.Data;

   namespace CShartNet2008GeneralApps
    {
      public partial class FrmDataGrid : Form
      {
         public FrmDataGrid()
        {
           InitializeComponent();
        }

     //connection variable and class instantiate
         private string connstr = "";
 private ClassConnectionString clsConnSrv; <-- Error   

 private void FrmDataGrid_Load(object sender, EventArgs e)
   {
     //instantiate class to retrieve SQL SERVER connection string                                              clsConnSrv = new ClassConnectionString 
 connstr = clsConnSrv.PropSQLSRVconnection; <--- Error connstr  
   }
   }
} 


Please help me to learn something new about CLASS in C#.NET.
Thank you very much.

Cheers,:P
Lennie











© net-tutorials.com 2006 - 2010