Click to See Complete Forum and Search --> : C#.NET2008 using CLASS to connect to SQLSERVER


LennieKuah
March 29th, 2010, 05:12 AM
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
}
}
}

boudino
March 29th, 2010, 09:53 AM
The connection string badly formed. It shoud be
clsGvConnstr += "Data Source = KuahFamily\\LocalHost";
or
clsGvConnstr += @"Data Source = KuahFamily\LocalHost";

LennieKuah
March 29th, 2010, 01:34 PM
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

LennieKuah
March 30th, 2010, 03:57 AM
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

boudino
March 30th, 2010, 08:11 AM
What is the error message exactly?

LennieKuah
March 30th, 2010, 04:20 PM
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?