Go Back   SitePoint Forums > Forum Index > Program Your Site > .NET
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 9, 2009, 00:56   #1
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
Red face ado dataset

hi all..m new to the comm..please help..


when i wroking with ado dataset m getting an error "unrecognised sequence error"..pls\ease help me out...
this is my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace datasetdem
{
public partial class datasetform : Form
{
SqlConnection con = new SqlConnection("Server=chinna\sqlexpress;database=MSNETDB1:User Id=sa;Password=dss;");

DataTable dt;
SqlDataAdapter daEmp;
DataSet ds;
DataRow dr;
public datasetform()
{
InitializeComponent();
}

private void datasetform_Load(object sender, EventArgs e)
{
SqlConnection Con = new SqlConnection();
Con.ConnectionString = Helper.ConnectionString;

try
{
con.Open();
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}

daEmp = new SqlDataAdapter("Select EmpId,EmpName,EmpSalary from Emp", con);
MessageBox.Show(daEmp.SelectCommand.CommandText);


ds = new DataSet();
daEmp.Fill(ds, "emp");
dt = ds.Tables[0];
dgEmp.DataSource = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
cmbEmpId.Items.Add(dr["EmpId"]);
}
}

private void dgEmp_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}


}
}
gundala_abhilash is offline   Reply With Quote
Old Nov 9, 2009, 00:57   #2
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
Red face

thanx in advance..do help me out
gundala_abhilash is offline   Reply With Quote
Old Nov 9, 2009, 01:09   #3
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
no one replying???plsss reply
gundala_abhilash is offline   Reply With Quote
Old Nov 9, 2009, 01:37   #4
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,587
You are closing your connection before you are using it. In the finally block and you do not have a catch block with your try. Should not give you that error, but sort that out and see what happens then.
NightStalker-DNS is offline   Reply With Quote
Old Nov 9, 2009, 02:00   #5
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
error is show in the red color

"Server=chinna\sqlexpress;database=MSNETDB1:User Id=sa;Password=dss;");
gundala_abhilash is offline   Reply With Quote
Old Nov 9, 2009, 10:23   #6
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
same error coming..help me out
gundala_abhilash is offline   Reply With Quote
Old Nov 9, 2009, 10:36   #7
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
Quote:
Originally Posted by gundala_abhilash View Post
hi all..m new to the comm..please help..


when i wroking with ado dataset m getting an error "unrecognised escape sequence error"..pls\ease help me out...
this is my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace datasetdem
{
public partial class datasetform : Form
{
SqlConnection con = new SqlConnection("Server=chinna\sqlexpress;database=MSNETDB1:User Id=sa;Password=dss;");

DataTable dt;
SqlDataAdapter daEmp;
DataSet ds;
DataRow dr;
public datasetform()
{
InitializeComponent();
}

private void datasetform_Load(object sender, EventArgs e)
{
SqlConnection Con = new SqlConnection();
Con.ConnectionString = Helper.ConnectionString;

try
{
con.Open();
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}

daEmp = new SqlDataAdapter("Select EmpId,EmpName,EmpSalary from Emp", con);
MessageBox.Show(daEmp.SelectCommand.CommandText);


ds = new DataSet();
daEmp.Fill(ds, "emp");
dt = ds.Tables[0];
dgEmp.DataSource = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
cmbEmpId.Items.Add(dr["EmpId"]);
}
}

private void dgEmp_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}


}
}
.
gundala_abhilash is offline   Reply With Quote
Old Nov 9, 2009, 13:26   #8
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,587
Try putting the connection string in the web.config file.

<connectionStrings>
<add name="ConnectionString" connectionString="Server=chinna\sqlexpress;database=MSNETDB1:User Id=sa;Password=dss;" />
</connectionStrings>

Then reference it like this:

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"]);
NightStalker-DNS is offline   Reply With Quote
Old Nov 9, 2009, 23:23   #9
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
@above

The name 'ConfigurationManager' does not exist in the current content


m getting this error
gundala_abhilash is offline   Reply With Quote
Old Nov 9, 2009, 23:25   #10
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
this is my app configuration file::

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="csMSNETDB" connectionString="server=chinna\sqlexpress;database=MSNETDB1"/>

</connectionStrings>
</configuration>

Last edited by gundala_abhilash; Nov 9, 2009 at 23:26. Reason: have to add code
gundala_abhilash is offline   Reply With Quote
Old Nov 9, 2009, 23:26   #11
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
this is my helper class.....


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


class Helper
{
public static string ConnectionString
{
get
{
return System.Configuration.ConfigurationManager.ConnectionStrings["csMSNETDB"].ConnectionString;

}
}
}
gundala_abhilash is offline   Reply With Quote
Old Nov 10, 2009, 00:57   #12
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,587
add:
using System.Configuration;
NightStalker-DNS is offline   Reply With Quote
Old Nov 10, 2009, 02:06   #13
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
hi nightstalker


yeah i idded using System.Configuration; bro..m getting 2 error messages if i add that::

Error 1 The best overloaded method match for 'System.Data.SqlClient.SqlConnection.SqlConnection(string)' has some invalid arguments .
Error 2 Argument '1': cannot convert from 'System.Configuration.ConnectionStringSettings' to 'string' ..


these r the errors m getting if i add System.Configuration;

wht should i do bro???
gundala_abhilash is offline   Reply With Quote
Old Nov 10, 2009, 03:26   #14
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,587
ConfigurationManager.ConnectionStrings["csMSNETDB"].ToString()
NightStalker-DNS is offline   Reply With Quote
Old Nov 10, 2009, 10:52   #15
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
ok bro..but i have build the project everything is fine but m getting
"object ref not set to an instance of an object" exception....
gundala_abhilash is offline   Reply With Quote
Old Nov 11, 2009, 09:02   #16
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
any one der to help me
gundala_abhilash is offline   Reply With Quote
Old Nov 11, 2009, 10:37   #17
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,587
well, on what line are you getting that error? And what version of asp.net are you using?
NightStalker-DNS is offline   Reply With Quote
Old Nov 11, 2009, 22:01   #18
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
studio 2008 version 3.5..

nullrefexception ...@ helper.helper.get_connection string..


bro i have send u the helper.class n app. configuration also..pls look at it
gundala_abhilash is offline   Reply With Quote
Old Nov 11, 2009, 23:17   #19
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
@nitestalker ....bro the above exception is rectified and my code is working...

but m getting "login failure for the user:the user is not associatd with a trusted sql server connection"...

bro is thr any mistake in ma connection creation???can u help me plssss
gundala_abhilash is offline   Reply With Quote
Old Nov 12, 2009, 10:49   #20
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
any body thr
gundala_abhilash is offline   Reply With Quote
Old Nov 12, 2009, 21:01   #21
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,587
That is a SQL permission issue. Probably got something 2 do with your connection string. To get the correct connectionstring for you db. Go here: http://www.connectionstrings.com/
NightStalker-DNS is offline   Reply With Quote
Old Nov 12, 2009, 22:29   #22
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
iam using " microsoft sql server(sqlclient)"

server name = chinna\SqlExpress

and in log on to the server wch type i shld use:::use windows authentication or use sql server authentication?????

user name ==????

password ===????


if i use windows authentication n database name::MSNETDB!..m getting test connection succeded but when i run the application m getting login failer for the user..and the user not associated with trusted sql server
gundala_abhilash is offline   Reply With Quote
Old Nov 12, 2009, 23:11   #23
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,587
That is because your app is running on an ASPNET/IIS guest account which is not a trusted connection to SQL.

Either, add that user as trusted in SQL server, or impersonate a user that is trusted in your website.

To do that add this to your web.config:

<identity impersonate="true" userName="username" password="password" />

You can use any username and password there that is trusted to sql, such as the current user account ur logged in with.
NightStalker-DNS is offline   Reply With Quote
Old Nov 13, 2009, 01:41   #24
gundala_abhilash
SitePoint Member
 
Join Date: Nov 2009
Posts: 20
how to add that user as trusted in SQL server...can u tell me plss
gundala_abhilash is offline   Reply With Quote
Old Nov 13, 2009, 01:47   #25
NightStalker-DNS
SitePoint Wizard
 
NightStalker-DNS's Avatar
 
Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,587
http://www.hosting.com/support/vps/windows/mixedmode/

Then use your original connection string.
NightStalker-DNS is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 09:37.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved