CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2005
    Posts
    46

    C#.NET2008 using CLASS to connect to SQLSERVER

    Hi Good Guys,

    I encounter another new 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 programe 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.

    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
    {
    // 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;
    }
    }
    }

    --------------------------------------------------
    // 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 ClassConnectionString

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

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: C#.NET2008 using CLASS to connect to SQLSERVER

    The connection string badly formed. It shoud be
    Code:
    clsGvConnstr += "Data Source = KuahFamily\\LocalHost";
    or
    Code:
    clsGvConnstr += @"Data Source = KuahFamily\LocalHost";
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  3. #3
    Join Date
    Jan 2005
    Posts
    46

    Re: C#.NET2008 using CLASS to connect to SQLSERVER

    Hi boudine,
    Thank you very much for the suggestion. Appreciate that very much.

    How about these 2 errors on these code: These coding are from the FORM instantiate the CLASSCONNECTIONSTRING to retrieve the connection string.

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

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


    Please help me. Need your help. Thanks,

    Cheers,
    Lennie

  4. #4
    Join Date
    Jan 2005
    Posts
    46

    Re: C#.NET2008 using CLASS to connect to SQLSERVER

    Lennie here,
    Regarding my coding problem posted above, Please help me, Here are additional information.
    My SERVER name is KUAHFAMILY\LOCALHOST.

    On FrmDataGrid.CS FORM I am trying to Instantiate the CLASSCONNECTIONSTRING and retrieve connection string from CLASS Method PROPADOCONNECTION.

    Under C#.NET2008, this is the first time I am using CLASS to retrieve SQL SERVER connection string.
    Please Help me.

    Cheers,
    Lennie
    Last edited by LennieKuah; March 30th, 2010 at 04:13 PM.

  5. #5
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: C#.NET2008 using CLASS to connect to SQLSERVER

    What is the error message exactly?
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  6. #6
    Join Date
    Jan 2005
    Posts
    46

    Re: C#.NET2008 using CLASS to connect to SQLSERVER

    Hi boudino,
    It's nice to hear from you again. Thank you very much.

    Here are the error messages:

    Error 1 'ClassConnectionString.ClassConn' is a 'type', which is not valid in the given context

    Error 2 Cannot convert method group 'PropAdoconnection' to non-delegate type 'string'. Did you intend to invoke the method?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured