Showing posts with label sqlconnection. Show all posts
Showing posts with label sqlconnection. Show all posts

Thursday, February 16, 2012

ASP.NET,Gettting Error in the Program

Hi,

please have look into the code and let me know the solution plz.

string

ProID;try

{

using(SqlConnection conn=new SqlConnection(source))

{

conn.Open();

DataSet ds=

new DataSet();

DDLProject.Items.Clear();

SqlCommand cmd=

new SqlCommand("SP_ProjectSelect",conn);

cmd.CommandType=CommandType.StoredProcedure;

cmd.Parameters.Add("Name",SqlDbType.NChar,30,"@.Name");

cmd.UpdatedRowSource=UpdateRowSource.None;

cmd.Parameters["Name"].Value=DDLProductLine.SelectedItem;

SqlDataReader dr=cmd.ExecuteReader(); ---->>>> Here iam getting Following Error.

while(dr.Read())

{ Response.Write(dr["ID"].ToString());

}

}

}

catch(System.Exception ex)

{

Response.Write(ex);

}

Error:

System.InvalidCastException: Object must implement IConvertible. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteReader() at MIS.UI.ResourceList.DDLProductLine_SelectedIndexChanged(Object sender, EventArgs e) in c:\inetpub\wwwroot\dotnet pgms\mis\ui\resourcelist.aspx.cs:line 121

Any suggestion plzz,where went wrong.

Thanks in advance

Regards

Mahesh Reddy

Is it possible your stored procedure "SP_ProjectSelect" is not returning a result set? That's what it sounds like.|||

I think your oder in parameter.add was not correct.

The order should be SQL parameter, DataType, and Input Value.

In your case, it looks like

cmd.Parameters.Add("@.Name",SqlDbType.NChar,30,Name);

Here, "@.Name" is SQL parameter name, Name is the valueable you want to input. You can use "Name" for test. In this case, you will insert "Name" into table.

Also, NChar is not the good datatype for string name. I suggest you change it to VarChar (You need change it in SQL SP too).

Hope it helps

asp.net worker process runs out of memory when using a large dataset

Hi,

I'm running an application on a server which grabs data from a database table on another server using SqlConnection, SqlDataAdapter and DataSet.

The application then updates every row in that DataSet's DataTable and the updates are saved back using DataAdapter. The code is pretty much straightforward code that you would find on MSDN documentation for using DataSets. The table contains a little over a million rows.

When I run the application, I get an error saying the Server Application is not available. Upon looking into the application event log, I get this message.

aspnet_wp.exe was recycled because memory consumption exceeded the
306 MB (60 percent of available RAM)

How do I get round this? I thought DataSets were supposed to handle large datatables comfortably without having memory issues.

-Thanks

They can, just increase your recycle point. Although with a million rows, it's likely you grind that little box into the ground. Buy more RAM, or expect to wait forever for a response. Using a DataReader instead of a dataset is what will allow your little box to access large tables without consuming a ton of memory.

ASP.NET SQLConnection string problem with ISP "oneandone.co.uk"

Appreciate this is probably one for the oneandone tech support team on Monday, but I'd like to avoid loosing a days development and deployment time by geting this sorted today if possible. Would really appreciate it if anyone can help?

When I try connecting to a SQL 2000 database supplied by my ISP I get an erro telling me the Server doesn't exist or I don't have acces. Am sure the problem lies with my connection string. Only problem is I've tried all possible variations using the "database name", "userid" and "password" supplied by oneandone. Their help pages give the following connection string example:

oConn = New System.Data.SQLClient.SQLConnection ("server=kundenmssql3.schlund.de; initial catalog=Northwind;uid=USERNAME;pwd=PASSWORD")

I've tried using my domain name for the server and the name they've provided in the example, all without any success. I can't find any information on what server name I should be using in my account maintenance area.

Does anyone else out there host with oneandone, and if so, can you point me in the right direction?

Thanks.you may need to specify the network library to use - try the page on this error at www.aspfaq.com

j

Monday, February 13, 2012

ASP.NET mini Form with SQL Server 2000

Hi, i have created a mini form to test out easy steps and my sqlconnection but something is wrong with my connection i think...
I am running windows XP Pro SP 2. i have Microsoft VisStudio .NET 2003fully installed and now im installing SQL Server 2000 DeveloprsEdition. I just cimpleted the installaion and picked some settings:
Local Computer Installation, Create new Instance since this is thefirst time i use it, Server and Client Tools, and chose a Local ratherthe Domain option aferwards. (i have used this version before but hadto format the comp so now reinstalling everything).
My problem is this, i basically started the server and it on online. iwent to the "enterprise manager" and in the "Microsoft SQL Servers-> SQWL Server Group -> (Local)(Windows NT)-> Databases, icreated a new database called tables and added a single table just tobegin testing to see if at least its functional. i was able to do thisso far.
Now i started my .NET, and wrote a tiny program to see if theconnection to the SQL database would open, but it didnt. It alwaysfailed. i am programming an ASP.NET WebApplication. I cant open theconnection to my database. i dont know why. (The tiny piece of code iwrote is at the bottom in case you know c#). There is a note alsounder the code for the ones who will read through its simlicity
any help or walk through would be appreciated. thank u...
Sam



CODE:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
namespace WebTest1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
string connection = ConfigurationSettings.AppSettings["ConnectionString"];


protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label outputBox;
protected System.Web.UI.WebControls.Label Label3;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
outputBox.Text = "Button has been clicked";
SqlConnection conn = new SqlConnection(connection);

outputBox.Text += "------Creating sql Connection";

try
{
conn.Open();
outputBox.Text += "-----opening the Connection";
}
catch(Exception p)
{
outputBox.Text += "-----failed to open Connection";
Console.WriteLine(p.ToString());
}
outputBox.Text += "----Success Connection and Login to Server!";

}
}
}


NOTE: i always get this output :
Button has been clicked------Creating sqlConnection-----failed to open Connection----SuccessConnection and Login to Server!
it skips the try block's print line which means it didnt work.....

string connection =ConfigurationSettings.AppSettings["ConnectionString"]; this one iupdated in my Web.config and included application setting line thatloox like this
<add key="ConnectionString" value="Data Source=127.0.0.1; Initial Catalog=login; User Id=sa; password=pass" />

You don't say what the error message is. Probably because you are catching it and not dealling with it. In your catch block you should output the p.Message to the outputBox for debugging purposes - Writing that to the console is not going to do any good as there isn't a Console.

You said you created a database called "tables". But your connection string is attempting to open a database called "login". If you do not have a database called "login" then the connection will fail.
I've never attempted to set the datasource to "127.0.0.1" before, so I cannot say if that is likely to be a problem. If I am connecting to the SQL Server on the local machine I always use "(local)"
Does this help?

|||

swy000 wrote:


string connection = ConfigurationSettings.AppSettings["ConnectionString"]; this one i updated in my Web.config and included application setting line that loox like this
<add key="ConnectionString" value="Data Source=127.0.0.1; Initial Catalog=login; User Id=sa; password=pass" />


I am not sure why you are using the loopback IP address 127.0.0.1 in your connection string when you can just use local host. In C# check out Programming .NET by Jeff Prosise for good sample code for Asp.net and the book written by the people who write the code for this site Coding strategies of the Asp.net team by Rob Howard and mathew Gibbs, for sample code for web applications in C#. Try the link below for sample connection strings. Hope this helps.
http://www.connectionstrings.com/