|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Member
Join Date: Nov 2009
Posts: 20
|
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) { } } } |
|
|
|
|
|
#2 |
|
SitePoint Member
Join Date: Nov 2009
Posts: 20
|
thanx in advance..do help me out
|
|
|
|
|
|
#3 |
|
SitePoint Member
Join Date: Nov 2009
Posts: 20
|
no one replying???plsss reply
|
|
|
|
|
|
#4 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() 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.
|
|
|
|
|
|
#5 |
|
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;"); |
|
|
|
|
|
#6 |
|
SitePoint Member
Join Date: Nov 2009
Posts: 20
|
same error coming..help me out
|
|
|
|
|
|
#7 | |
|
SitePoint Member
Join Date: Nov 2009
Posts: 20
|
Quote:
|
|
|
|
|
|
|
#8 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() 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"]); |
|
|
|
|
|
#9 |
|
SitePoint Member
Join Date: Nov 2009
Posts: 20
|
@above
The name 'ConfigurationManager' does not exist in the current content m getting this error |
|
|
|
|
|
#10 |
|
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 |
|
|
|
|
|
#11 |
|
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; } } } |
|
|
|
|
|
#12 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,587
|
add:
using System.Configuration; |
|
|
|
|
|
#13 |
|
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??? |
|
|
|
|
|
#14 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,587
|
ConfigurationManager.ConnectionStrings["csMSNETDB"].ToString()
|
|
|
|
|
|
#15 |
|
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.... |
|
|
|
|
|
#16 |
|
SitePoint Member
Join Date: Nov 2009
Posts: 20
|
any one der to help me
|
|
|
|
|
|
#17 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() 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?
|
|
|
|
|
|
#18 |
|
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 |
|
|
|
|
|
#19 |
|
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 |
|
|
|
|
|
#20 |
|
SitePoint Member
Join Date: Nov 2009
Posts: 20
|
any body thr
|
|
|
|
|
|
#21 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() 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/
|
|
|
|
|
|
#22 |
|
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 |
|
|
|
|
|
#23 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() 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. |
|
|
|
|
|
#24 |
|
SitePoint Member
Join Date: Nov 2009
Posts: 20
|
how to add that user as trusted in SQL server...can u tell me plss
|
|
|
|
|
|
#25 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: Cape Town, South Africa
Posts: 1,587
|
|
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 09:37.









Linear Mode
