|
its still the same saying it has not been initialise...
is executedscaler very hard to use?
i been trying out for veri long still cannot work
the asp.net2 developers makes displaying multiple data in datagrid so easy yet they forgot to make dispalying single data easy.....
|
|
|
|
|
For,
neodeaths wrote: SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"));
Use,
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"]);
|
|
|
|
|
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"]);<br />
<br />
SqlCommand command = new SqlCommand("Select CurrentNo From LookUpID Where TypeID = 'AuctionSessionID'",conn);<br />
conn.Open();<br />
string result = command.ExecuteScalar().ToString();<br />
Label2.Text = result;<br />
conn.Close();
error:Error 59 Argument '1': cannot convert from 'System.Configuration.ConnectionStringSettings' to 'string'
and
Error 58 The best overloaded method match for 'System.Data.SqlClient.SqlConnection.SqlConnection(string)' has some invalid arguments
now these 2 errors...
|
|
|
|
|
Can you send the content of your web.config file? I have a doubt whether you have the key with name "ConnectionString"...
|
|
|
|
|
please know taht i am using asp.net2 (2005) with sql server 2005 thx
<?xml version="1.0" encoding="utf-8"?><br />
<configuration xmlns=<br />
"http://schemas.microsoft.com/.NetConfiguration/v2.0"><br />
<connectionStrings><br />
<add name="HASDBConnectionString1" connectionString="Data Source=------\SQLEXPRESS;Initial Catalog=HASDB;Persist Security Info=True;User ID=sa;Password=---"<br />
providerName="System.Data.SqlClient" /><br />
</connectionStrings><br />
<system.web><br />
<authorization><br />
<allow roles="Registrator" /><br />
<deny users="*" /><br />
</authorization><br />
</system.web><br />
</configuration>
the above is my web.config in the subfolder where the page i am working on is
<?xml version="1.0"?><br />
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"><br />
<connectionStrings><br />
<add name="HASDBConnectionString1" connectionString="Data Source=---\SQLEXPRESS;Initial Catalog=HASDB;Persist Security Info=True;User ID=sa;Password=---"<br />
providerName="System.Data.SqlClient" /><br />
</connectionStrings><br />
<system.web><br />
<br />
<membership defaultProvider="MyMembershipProvider"><br />
<providers><br />
<add name="MyMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="HASDBConnectionString1" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" /><br />
</providers><br />
</membership><br />
<br />
<br />
<br />
<br />
<roleManager enabled="true" defaultProvider="MyMembershipProvider"><br />
<providers><br />
<add name="MyMembershipProvider" connectionStringName="HASDBConnectionString1" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /><br />
<add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /><br />
</providers><br />
</roleManager><br />
<authentication mode="Forms" /><br />
<compilation debug="true"/><br />
<authorization><br />
<br />
<deny users="?" /><br />
</authorization><br />
<br />
</system.web> <br />
<system.net><br />
<br />
<mailSettings><br />
<br />
<smtp><br />
<network host="my.mail.server" /><br />
</smtp><br />
</mailSettings><br />
</system.net><br />
</configuration>
this is the web.config of my main project
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionStrings"]);<br />
SqlCommand command = new SqlCommand("Select CurrentNo From LookUpID Where TypeID = 'AuctionSessionID'",conn);<br />
conn.Open();<br />
string result = command.ExecuteScalar().ToString();<br />
Label2.Text = result;<br />
conn.Close();
The ConnectionString property has not been initialized.
|
|
|
|
|
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connectionStrings"]);
by the way for my knowledge =P
what does the above code the part where i underline stand for?
is it something in the web.config?
or an variable?
|
|
|
|
|
neodeaths wrote: SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connectionStrings"]);
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HASDBConnectionString1"]);
Do not use ConfigurationManager.AppSettings as you have placed the key inside connectionStrings section of the configuration file.
neodeaths wrote: SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionStrings"]);
The ConnectionString is the key name you specified in the web.config file in the connectionStrings section. In your configuration file you are using HASDBConnectionString1 as the key name.
|
|
|
|
|
firstly:
after i change it to<br />
SqlConnection conn = new SqlConnection("HASDBConnectionString1 ");<br />
SqlCommand command = new SqlCommand("Select CurrentNo From LookUpID Where TypeID = 'AuctionSessionID'",conn);
i changed it to the above code and a new error appear at runtime.
Format of the initialization string does not conform to specification starting at index 0.
2nd:
so if i get u rite the configurationmanager.appsetting is a method that will use the specified connectionstring which is in the root folder?
3rd: i appreciated ur pateint with my noobish question =)
|
|
|
|
|
neodeaths wrote: SqlConnection conn = new SqlConnection("HASDBConnectionString1 ");
This is wrong. I am afraid whether you know .NET or not.
Use like this,
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HASDBConnectionString1"]);
|
|
|
|
|
!!
it works now thx
SqlConnection conn = new SqlConnection((ConfigurationManager.ConnectionStrings["HASDBConnectionString1"]).ToString());
and by the way the first argument need to be change to a string first be4 used
but thx for everything really appreiciated it
at the mean time i am gonna go read and test the executescaler method more thx alot
|
|
|
|
|
It is something in the web.config. If it doesn't exist then your code won't work. You really should abstract that kind of all out into a configuration class that can handle events such as missing configuration elements.
|
|
|
|
|
hi,
If you are using Asp.Net 2.0 your code
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"));
should be
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString());
next I dont know abt the code you are using in web.config if it can work that way but here is what I use
<configuration>
<appSettings>
<add key="connectionString" value="initial catalog=----;data source=---;user id=---;password=---;">
</add>
</appSettings>
</configuration>
try by changing the first code only see if that works
Regards,
Maggi
|
|
|
|
|
Hi there!
I have deployed my site on an IIS server.
And its working fine.
But I don't know how to access it from other machines..
I have tried accessing by
http://192.168.1.28
where the number is the IP of the IIS server.
Thanks for your help..
You don't have to be AFRAID!
|
|
|
|
|
Try like this
http://192.168.1.28/yourvirtualdirectory/home.aspx
OR
http://yoursysname/yourvirtualdirectory/home.aspx
|
|
|
|
|
Which is the Operating System of your Webserver (IIS Server)?
If it is Windows XP (SP2 Installed), the personal firewall blocks the other machine to connect the server through the port 80 (TCP/IP default port). You have set exception in the firewall to the 80 port.
|
|
|
|
|
Hello, I am trying to enable/disable a textbox prior to the page rendering based on its value. To be able to access the textbox value I had to implement this in Page_LoadComplete event of the page. After the enable/disable logic in Page_LoadComplete I obtain a boolean value that I save to ViewState and access it from Page.IsPostBack( ) method of Page_Load. I tried using ViewState to save the value as string and retrieve it in Page.IsPostBack( ) method but I am getting a NullReferenceException meaning the value of the ViewState variable is null. Why is the state not saving in ViewState variable? Here is my Page_LoadComplete method:
public void Page_LoadComplete(object sender, System.EventArgs e)
{
//Here I obtain value of textbox and based on it's value enable or disable the textbox
//Obtain a boolean value that I need to pass to Page.IsPostBack( ) method of Page_Load
ViewState["istempVar"] = aboolValue;
}
I am trying to access this ViewState variable in:
public void Page_Load(object sender, System.EventArgs e)
{
...
if (Page.IsPostBack )
{
// obtain ViewState["istempVar"]
}
Any help is appreciated.
Thanks.
|
|
|
|
|
tjkota wrote: I save to ViewState and access it from Page.IsPostBack( )
The LoadComplete event occurs after all postback data and view-state data is loaded into the page and all controls on the page. In order for view state to work for controls that are added dynamically, they must be added in or before the pre-render stage of the page life cycle.
|
|
|
|
|
Hi I am getting an error in my website that i dont understand.
The message is here on line 53 in web.config - I use similar assemblies previous to this in the file such as System.Web.Security.SqlMembershipProvider
and the type below can be called from .cs pages. Any ideas?
Thanks
Dan
Server Error in '/TraffordCentre' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
Source Error:
Line 51: connectionStringName="LocalSqlServer"
Line 52: applicationName="/"
Line 53: type="System.Web.Security.SqlRoleProvider,
Line 54: System.Web.Version=2.0.0.0, Culture=neutral,
|
|
|
|
|
Hi,
i want to notify user (and so update user session) when another user was update data(data in her session).
(like create a listner turning in application server how fire event when each user update her session, and so each user catch this event and modifi data !!!!)
thks for help
Developper
|
|
|
|
|
Good luck with that.
You probably can't create a viable "listener" in a web environment. Implement some form of record locking to prevent multiple people from updating the same record and update your display periodically (every 30 seconds or so). That's probably the best you can do.
|
|
|
|
|
|
Is it possible to edit the element in a page built using code behind?
Thanks,
A
|
|
|
|
|
Yes. There is a Page variable that has a Header object.
Here is a sample from MS help:
Visual Basic
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim bodyStyle As New Style()
bodyStyle.ForeColor = System.Drawing.Color.Blue
bodyStyle.BackColor = System.Drawing.Color.LightGray
Page.Header.StyleSheet.CreateStyleRule(bodyStyle, Nothing, "BODY")
Page.Header.Title = "HtmlHead Example"
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1"
runat="server">
<title>To be replaced.</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>HtmlHead Class Example </h3>
<asp:label id="Label1"
text = "View the HTML source code of this page to see the title
and body style added to the header element."
runat="server">
</asp:label>
</form>
</body>
</html>
C#
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, System.EventArgs e)
{
Style bodyStyle = new Style();
bodyStyle.ForeColor = System.Drawing.Color.Blue;
bodyStyle.BackColor = System.Drawing.Color.LightGray;
Page.Header.StyleSheet.CreateStyleRule(bodyStyle, null, "BODY");
Page.Header.Title = "HtmlHead Example";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1"
runat="server">
<title>To be replaced.</title>
</head>
<body>
<form runat="server">
<h3>HtmlHead Class Example</h3>
<asp:label id="Label1"
text = "View the HTML source code of this page to see the title
and body style added to the header element."
runat="server">
</asp:label>
</form>
</body>
</html>
Hope that helps.
Ben
|
|
|
|
|
Thanks Ben, just what I needed.
Alice
|
|
|
|
|
I am new to ASP.Net and learning on my own.
Is there any code or tutorial anywhere on the net on ASP.Net that encompasses every knowledge to build a simple small website; from graphics design to deployment.
Thank You!
X
|
|
|
|