Going Nuts - The ConnectionString Property Has Not Been Initialized - Help!
May 27, 2006
I'm struggling with the different methodologies for using DataSets in 2.0. I can knock this out in no time flat in 1.0, but am bogged down in 2.0. Can anyone guide me on the right track? My code is below. I'm forming a DataSet from a SQL Server Express database from the user's choice from a drop down. My connection string "ASOCTCOConnectionString" is declared in my web.config and used successfully throughout in the WYSIWYG configurations of my databound controls. But I want to control this in code. This si getting frustrating and right now I'm longing for the clean simplicity I had with Web Matrix :(
In any case, any suggestions? It crashes with this error when opening the connection with MyConn.Open(). I just want to be able to configure a DataSet and apply it to my controls and results.
<code>
Dim connectionString As String = System.Configuration.ConfigurationManager.AppSettings("ASOCTCOConnectionString")
Dim MyConn As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim MyQuery, SearchString As String
Dim myAdapter As New System.Data.SqlClient.SqlDataAdapter
Dim myDataSet As New System.Data.DataSet
Dim mySelectCommand As New System.Data.SqlClient.SqlCommand
mySelectCommand.CommandText = "SELECT * from Device_Type where Category LIKE " & DDLDevType.SelectedItem.Text
mySelectCommand.Connection = MyConn
MyConn.Open()
Grid1.DataSource = myDataSet
Grid1.Databind()
MyConn.Close()
</code>
View 11 Replies
ADVERTISEMENT
Jul 30, 2007
In short, I have a couple grid views on a page that are used for editing as well as sorting, etc. The grids are setup to use the SqlDataSources. I'm trying to deploy this to a server environment for different instances (test,cert,prod) and am trying to set the ConnectionString for the SqlDataSource in the code behind (Page_Load()). Everything works well, except, I get an error message that says the "ConnectionString Property Has Not Been Initialized." Its a javascript alert coming up on top of the grid view.
Here is how I'm trying to set the ConnString in the Page_Load():this.EmployeeTimeCardDataSource.ConnectionString = ConfigurationManager.ConnectionStrings[connStr].ConnectionString;
Here is an example of the DataSource.<asp:SqlDataSource ID="EmployeeTimeCardDataSource" runat="server" SelectCommand="sp_Select_Managers_Employees_List" SelectCommandType="StoredProcedure"> <SelectParameters> <asp:SessionParameter Name="CurrentUser" SessionField="User" Type="String" /> </SelectParameters></asp:SqlDataSource>
View 5 Replies
View Related
Oct 22, 2007
I am getting an error message that says that my connection string has not been intialized I have initialized it.
Dim AirliquidiConn As New SqlClient.SqlConnection(ConfigurationManager.AppSettings("AirliquidiDatabase"))
Any suggestions??
View 10 Replies
View Related
Jan 25, 2008
Hi all
This is the code in my web.config file.
<appSettings> <add key="ConnectionString" value="server=127.0.0.1;database=testdb;uid=sa;pwd=sa"/> </appSettings>
When I'm connecting to the sqlserver database,the page shows that The ConnectionString property has not been initialized.
The code that I used to get the "ConnectionString" as belows
using System.Configuration;
protected static string connectionString =ConfigurationSettings.AppSettings["ConnectionString"];
public static object GetSingle(string SQLString,params SqlParameter[] cmdParms) { using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { try { PrepareCommand(cmd, connection, null,SQLString, cmdParms); object obj = cmd.ExecuteScalar(); cmd.Parameters.Clear(); if((Object.Equals(obj,null))||(Object.Equals(obj,System.DBNull.Value))) { return null; } else { return obj; } } catch(System.Data.SqlClient.SqlException e) { throw new Exception(e.Message); } } } }
These code works well on my machine.When running on my colleague's machine ,the page show that exception.
Any ideal?
View 3 Replies
View Related
Mar 21, 2008
I tried to insert my inputs into the database but it says "The ConnectionString property has not been initialized."
These are my codes:
SubmitAssigment.aspx.vb
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conn As SqlConnection Dim mycmd As SqlCommand Dim dr As SqlDataReader Dim str As String conn = New SqlConnection(Configuration.ConfigurationManager.AppSettings("ConnectionString")) conn.Open() str = "INSERT INTO [UploadInfo] ([StudentID], [Subject], [Assigment], [File], [Upload], [Time]) VALUES (@StudentID, @Subject, @Assigment, @File, @Upload , @Time )" mycmd = New SqlCommand(str, conn) mycmd.Parameters.Add("@StudentID", Data.SqlDbType.VarChar, 500).Value = User.Identity.Name mycmd.Parameters.Add("@Subject", Data.SqlDbType.VarChar, 500).Value = DropDownList1.SelectedValue mycmd.Parameters.Add("@Assigment", Data.SqlDbType.VarChar, 500).Value = DropDownList2.SelectedValue mycmd.Parameters.Add("@File", Data.SqlDbType.VarChar, 500).Value = File1.PostedFile.FileName mycmd.Parameters.Add("@Upload", Data.SqlDbType.VarChar, 500).Value = "Yes" mycmd.Parameters.Add("@Time", Data.SqlDbType.VarChar, 500).Value = System.DateTime.Now dr = mycmd.ExecuteReader() mycmd.Dispose() dr.Close() End Sub
SubmitAssigment.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SubmitAssigment.aspx.vb" Inherits="Student_SubmitAssigment" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title> <style type="text/css"> .style1 { width: 100%; } .style2 { width: 70px; } .style3 { width: 106px; } </style></head><body> <form id="Form1" method="post" enctype="multipart/form-data" runat="server"> <p> </p> <table class="style1"> <tr> <td class="style2"> Subject:</td> <td> <asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="253px"> <asp:ListItem Selected="True">Select one....</asp:ListItem> <asp:ListItem>TCP2411 - Programming Language Concept</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td class="style2"> Assigment</td> <td> <asp:DropDownList ID="DropDownList2" runat="server" Height="16px" Width="105px"> <asp:ListItem Selected="True">Select one....</asp:ListItem> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem></asp:ListItem> </asp:DropDownList> </td> </tr> </table><p> </p> <input type= "file" id= "File1" name= "File1" runat="server" /> <br /><br /> <asp:Button ID="Submit1" runat="server" Text="Upload" /> <br /> <br /> <br /> <asp:LoginName ID="LoginName" runat="server" /> <br /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [UploadInfo] WHERE [StudentID] = @original_StudentID AND [Subject] = @original_Subject AND [Assigment] = @original_Assigment AND [File] = @original_File AND [Upload] = @original_Upload AND [Time] = @original_Time" InsertCommand="INSERT INTO [UploadInfo] ([StudentID], [Subject], [Assigment], [File], [Upload], [Time]) VALUES (@StudentID, @Subject, @Assigment, @File, @Upload , @Time))" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [StudentID], [Subject], [Assigment], [File], [Upload], [Time] FROM [UploadInfo]" UpdateCommand="UPDATE [UploadInfo] SET [Subject] = @Subject, [Assigment] = @Assigment, [File] = @File, [Upload] = @Upload, [Time] = @Time WHERE [StudentID] = @original_StudentID AND [Subject] = @original_Subject AND [Assigment] = @original_Assigment AND [File] = @original_File AND [Upload] = @original_Upload AND [Time] = @original_Time"> <DeleteParameters> <asp:Parameter Name="original_StudentID" Type="String" /> <asp:Parameter Name="original_Subject" Type="String" /> <asp:Parameter Name="original_Assigment" Type="String" /> <asp:Parameter Name="original_File" Type="Object" /> <asp:Parameter Name="original_Upload" Type="String" /> <asp:Parameter Name="original_Time" Type="DateTime" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Subject" Type="String" /> <asp:Parameter Name="Assigment" Type="String" /> <asp:Parameter Name="File" Type="Object" /> <asp:Parameter Name="Upload" Type="String" /> <asp:Parameter Name="Time" Type="DateTime" /> <asp:Parameter Name="original_StudentID" Type="String" /> <asp:Parameter Name="original_Subject" Type="String" /> <asp:Parameter Name="original_Assigment" Type="String" /> <asp:Parameter Name="original_File" Type="Object" /> <asp:Parameter Name="original_Upload" Type="String" /> <asp:Parameter Name="original_Time" Type="DateTime" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name ="StudentID" Type="String" /> <asp:Parameter Name ="Subject" Type="String" /> <asp:Parameter Name ="Assigment" Type="String" /> <asp:Parameter Name ="File" Type="Object" /> <asp:Parameter Name ="Upload" Type="String" /> <asp:Parameter Name ="Time" Type="DateTime" /> </InsertParameters> </asp:SqlDataSource> <table class="style1"> <tr> <td class="style3"> <asp:Button ID="Button1" runat="server" Text="Confirm" Width="68px" style="height: 26px" /> </td> <td> </td> </tr> <tr> <td class="style3"> </td> <td> </td> </tr> </table> <br /></form> </body></html>
Can anyone help me out?
Pleasee
Thannkss...
View 2 Replies
View Related
Nov 18, 2005
My IT dept set up an SQL db on a server for me and I am connected to it through a port. They told me I had to create my tables through an MS Access adp, which I have done. I am using VWD Express and am trying to create a login page using usernames and pw's from a db table. I am connected (at least the db Explorer tab shows I am) to the MS Access adp and can drop a GridView from my Employees table from it onto a page and get results. I keep getting the "ConnectionString property not initialized" error message pointing to my sqlConn.Open() statement and cannot figure out why. I have looked at hundreds of posts but can't seem to find anything that works. If someone could point me to some post or website that could explain connecting to a SQL db through a port or whatever you think I need to learn to get this fixed I would appreciate it. Web config:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>
<connectionStrings>
<add name="ASPNETDB" connectionString="Description=Training;DRIVER=SQL Server;SERVER=USAWVAS27;UID=usx14611;APP=Microsoft® Visual Studio® 2005;WSID=983QD21;Network=DBMSSOCN;Address=USAWVAS27,3180;Trusted_Connection=Yes" providerName="System.Data.Odbc" />
</connectionStrings>
<system.web>
<authentication mode="Forms" />
<authorization>
<deny users="?" />
</authorization>
<customErrors mode="Off" />
</system.web>
</configuration>My login.aspx page
<%@ Page Language="VB" debug="true"%>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Configuration.ConfigurationManager" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub LoginUser(ByVal s As Object, ByVal e As EventArgs)
Dim blnAuthenticate As Boolean = Authenticate(username.Text, password.Text)
If blnAuthenticate Then
FormsAuthentication.RedirectFromLoginPage(username.Text, False)
End If
End Sub
Function Authenticate(ByVal strUsername As String, ByVal strPassword As String) As Boolean
Dim strConnection As String = ConfigurationManager.AppSettings("ASPNETDB")
Tried this code as wellDim sqlConn As New SqlConnection(ConfigurationManager.AppSettings("ASPNETDB"))
Dim sqlConn As New SqlConnection(strConnection)
Dim sqlCmd As SqlCommand
Dim sqlDR As SqlDataReader
Dim userFound As Boolean
sqlCmd = New SqlCommand("SELECT * FROM Employees " & _
"WHERE username='" & strUsername & " ' AND password='" & strPassword & "'", sqlConn)
sqlConn.Open()
sqlDR = sqlCmd.ExecuteReader()
userFound = sqlDR.Read()
sqlDR.Close()
Return userFound
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>Username:<asp:TextBox ID="username" runat="server"></asp:TextBox><br />
<br />
<p>Password:<asp:TextBox ID="password" runat="server"></asp:TextBox><br />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Login" OnClick="LoginUser" /> </div>
</form>
</body>
</html>Thanks
View 5 Replies
View Related
Feb 5, 2006
I have installed SQL Server 2005 Express Edition.I have defined the connectionstring in my web.config as follows:
<connectionStrings><add name="MyDB" connectionString="Server=local;Provider=SQLOLEDB;Initial Catalog=Shop;Trusted_Connection=Yes;DataSource==.SQLExpress;AttachDBFilename=Data/MyDB.mdf" providerName="System.Data.SqlClient"/></connectionStrings>Here's my vb code:
Dim connStr As String = ConfigurationManager.ConnectionStrings("MyDB").ToString()Dim DBConnection As New SqlConnectionDim SQLCmd As New SqlCommand("SELECT * FROM tblMember WHERE UserName=@UserName", DBConnection)SQLCmd.Parameters.Add(New SqlParameter("@UserName", tbUserName.Text))DBConnection.Open()and on that last line I receive the error: The ConnectionString property has not been initializedNow, I have seen SO many different versions of a connectionstring that im totally confused!!I want to use windows authentication (I know thats better for security reasons).But I have difficulties understanding the attributes required (AND THEIR MEANING!) of the connectionstring. (e.g. do I need to define DataSource or Initial Catalog or AttachDBFileName and the rest? What does it do exactely?)Also: I have registered my server as "MyServer" is that the alias I need/can use in my connectionstring?If someone could explain me the above questions it would be of GREAT help!!
View 6 Replies
View Related
Apr 19, 2006
Hello, I have just begun my first web application in vs 2005. I have a done a bit of coding in VS 2003. I have some list boxes on the page that use an ObjectDatasource that I set up with the wizard--and they work well and connect to SQL server. But I wanted to re use some of my old code for another list box on the page and put code in myself.
Dim MyConnection As SqlConnection = New SqlConnection(ConfigurationManager.AppSettings("CONN_DATAConv"))
Dim ProcConnection As SqlConnection = New SqlConnection(ConfigurationManager.AppSettings("CONN_DATAConv"))
Dim myCommand As New SqlCommand(CommandText, MyConnection)
MyConnection.Open()
ProcConnection.Open() Here is what is in the web.config <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>
<connectionStrings>
<add name="DataConvConnectionString_gisad" connectionString="Data Source=PWDGIS4;Initial Catalog=DataConv;Persist Security Info=True;User ID=gisad;Password=erv11new"
providerName="System.Data.SqlClient" />
<add name="CONN_DATAConv" connectionString="Data Source=PWDGIS4;Initial Catalog=DataConv;Persist Security Info=True;User ID=gisad;Password=erv11new"
providerName="System.Data.SqlClient" />
</connectionStrings>
Please note that I canged the connection string call from
ConfigurationSettingsAppSettings that was in vs 2003
But the connections won't open. Any help would be greatly appreciated.
View 3 Replies
View Related
Apr 28, 2008
Hi,
I'm writing a sample code to try to connect to my local SQL 2005 Express server and run into the following error code
*******
Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.
*******
My app is fairly easy since I'm still a newbie to SQL
using System;
using System.Configuration;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
public class MovieDataReader
{
private readonly string _conString;
public SqlDataReader GetMovies()
{
SqlConnection con = new SqlConnection(_conString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT Title,Director FROM Movies";
con.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
public MovieDataReader()
{
SqlConnection con = new SqlConnection(@"Data Source=""ANDREW_JRSQLEXPRESS"";Integrated Security=True;Initial Catalog=Movies");
SqlCommand cmd = new SqlCommand("INSERT INTO Movies VALUES ('Steven Spielberg', 'Star War')", con);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
}
Can somebody please point out what I'm doing wrong here, thanks!
View 5 Replies
View Related
Apr 17, 2008
Hello,
am trying to run a SP in my class against my database.
However, I get the error below.
The connection string is in the web.config file as thus
<connectionStrings> <add name="cell_ConnectionString" connectionString="Data Source=xxx.xxx.xxx.xxx,2433;Network Library=DBMSSOCN;Initial Catalog=day;User ID=day;Password=jdhje5rhydgd;" providerName="System.Data.SqlClient"/> </connectionStrings>
and the connection string name is called in my class as thus
1 SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["cell_ConnectionString"]);
2
3 SqlCommand command = new SqlCommand("cell_ConnectionString", con);
4 command.CommandType = CommandType.StoredProcedure;
5
What is wrong here ?
thanks
Ehi
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.Source Error:
Line 49: command.CommandType = CommandType.StoredProcedure;
Line 50:
Line 51: con.Open();
Line 52:
Line 53: command.Parameters.Add(new SqlParameter("@csv", SqlDbType.VarChar, 8000, "recipients"));
Source File: c:inetpubwwwrootizevwwwrootwelcomesms.aspx.cs Line: 51
View 2 Replies
View Related
Feb 9, 2006
Hi,
I'm trying to do a database operation in ASP.NET page using the following code:
string connString = "SERVER=localhost;DATABASE=chbr;UID=sa;PWD=password;Connection Timeout=120";SqlConnection sqlConn = new SqlConnection(connString);sqlConn.Open();
string commandStr = "...";
SqlCommand command = new SqlCommand(commandStr); command.ExecuteNonQuery();sqlConn.Close();
But I kept getting the exception saying "ExecuteNonQuery: Connection property has not been initialized."
What did I do wrong?
Thanks!
View 1 Replies
View Related
Jan 2, 2007
Dear all,
I'm using ASP.net 2003, I need to display some of the messages that retrieve from a table in my sql server 2k. When I run the program, it works fine, but all of the messages that are supposed to get from the db table were not show. Below is my connection string in web config :
<add key="dbconn" value="data source=localhost;initial catalog=MyWeb;Min Pool Size=3;Max Pool Size=20;Pooling=true;password=mypassword;persist security info=True;user id=sa;workstation id=local" />
Any help will be greatly appreciated
View 3 Replies
View Related
Jan 2, 2007
Dear all,
I'm using ASP.net 2003, I need to display some of the messages that retrieve from a table in my sql server 2k. When I run the program, it works fine, but all of the messages that are supposed to get from the db table were not show. Below is my connection string in web config :
<add key="dbconn" value="data source=localhost;initial catalog=MyWeb;Min Pool Size=3;Max Pool Size=20;Pooling=true;password=mypassword;persist security info=True;user id=sa;workstation id=local" />
Any help will be greatly appreciated
View 5 Replies
View Related
May 21, 2007
Hi ,
Iam new to vs2005. Iam trying to integrate Authorize.net for transactions in my site. When i tested it worked fine .But when i put it in live for Amex cards it is giving me sqlerror.
Here is my code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Net;
using System.IO;
public partial class Paymentprocessing : System.Web.UI.Page
{SqlConnection objConn = new SqlConnection(ConfigurationManager.AppSettings["strConn"]);
string permLevel = "";protected void Page_Load(object sender, EventArgs e)
{if (Session["displayname"] == null || Session["franchiseid"] == null || Session["username"] == null)
{Response.Redirect("Default.aspx");
}
else
{lblusrname.Text = Session["displayname"].ToString();
}string strSelectquery = "";
strSelectquery = "select userPermissionLevel,Franchise_ID from tblUsers where User_Name='" + Session["username"].ToString()+"'";SqlCommand objCmd = new SqlCommand(strSelectquery, objConn);SqlDataReader objDr;
objConn.Open();
objDr = objCmd.ExecuteReader();
if (objDr.Read())
{
permLevel = objDr[0].ToString();
}
objDr.Close();
objConn.Close();if (int.Parse(permLevel) == 99)
{pnlRefundCC.Visible = true;
pnlRefundCA.Visible = true;pnlTransact.Visible = true;
pnlPaymentInfo.Visible = true;pnlCardifo.Visible = true;
}
else
{pnlPaymentInfo.Visible = true;
pnlCardifo.Visible = true;pnlRefundCC.Visible = false;
pnlRefundCA.Visible = false;pnlTransact.Visible = false;
}
}protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
{pnlTransact.Visible = false;
pnlPaymentCCA.Visible = false;pnlOrgTransID.Visible = true;pnlCardifo.Visible = true;
}protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{pnlOrgTransID.Visible = false;pnlPaymentCCA.Visible = false;
}protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
pnlPaymentInfo.Visible = false;pnlTransact.Visible = false;
pnlPaymentCCA.Visible = true;pnlDriversCCA.Visible = true;
}protected void RadioButton4_CheckedChanged(object sender, EventArgs e)
{pnlPaymentInfo.Visible = true;
pnlTransact.Visible = false;pnlOrgTransID.Visible = true;
pnlCardifo.Visible = false;pnlPaymentCCA.Visible = true;pnlDriversCCA.Visible = false;
}protected void btnSubmit_Click(object sender, EventArgs e)
{
string strSelect = "";strSelect = "select franchiseAuthNetID,franchiseAuthNetKey from franchises where franchiseid=" + Session["franchiseid"];
SqlCommand objCmd = new SqlCommand(strSelect, objConn);SqlDataReader objDr;
objConn.Open();
objDr = objCmd.ExecuteReader();String x_login = "";
String x_tran_key = "";if (objDr.Read())
{
x_login = objDr[0].ToString();
x_tran_key = objDr[1].ToString();
}
objDr.Close();
objConn.Close();
/***************************************************************
VARIABLES USED THROUGHOUT THIS SCRIPT
**************************************************************/String x_version = "3.1";
String x_test_request = "false"; // needs to be set to false when in productionString x_delim_data = "true";
String x_delim_char = "|";String x_relay_response = "false";
String x_first_name = txtFirstname.Text;String x_last_name = txtLastname.Text;
String x_company = txtCompany.Text;String x_address = txtAddress.Text;
String x_city = txtCity.Text;String x_state = txtState.Text;
String x_zip = txtZip.Text;String x_country = txtCountry.Text;
String x_phone = txtPhone.Text;String x_fax = txtFax.Text;
String x_cust_id = "";String x_customer_ip = Request.ServerVariables["REMOTE_ADDR"];
String x_customer_tax_id = txtTaxid.Text;String x_email = txtEmail.Text;
String x_email_customer = "true";String x_merchant_email = "help@XYZ.com";
String x_invoice_num = txtInvoiceno.Text;String x_description = txtInvoicedesc.Text;
String x_ship_to_first_name = "";String x_ship_to_last_name = "";
String x_ship_to_company = "";String x_ship_to_address = "";
String x_ship_to_city = "";String x_ship_to_state = "";
String x_ship_to_zip = "";String x_ship_to_country = "";if (CheckBox1.Checked)
{
x_ship_to_first_name = txtFirstname.Text;
x_ship_to_last_name = txtLastname.Text;
x_ship_to_company = txtCompany.Text;
x_ship_to_address = txtAddress.Text;
x_ship_to_city = txtCity.Text;
x_ship_to_state = txtState.Text;
x_ship_to_zip = txtZip.Text;
x_ship_to_country = txtCountry.Text;
}
else
{
x_ship_to_first_name = txtShippingfirstname.Text;
x_ship_to_last_name = txtShippinglastname.Text;
x_ship_to_company = txtShippingcompany.Text;
x_ship_to_address = txtShippingaddress.Text;
x_ship_to_city = txtShippingcity.Text;
x_ship_to_state = txtShippingstate.Text;
x_ship_to_zip = txtShippingzip.Text;
x_ship_to_country = txtShippingcountry.Text;
}String x_amount = "";
String x_method = "";if (RadioButton1.Checked == true || RadioButton3.Checked == true)
{
x_amount = txtAmount.Text;x_method = "CC";
}else if (RadioButton2.Checked == true || RadioButton4.Checked == true)
{
x_amount = txtCCAamount.Text;x_method = "ECHECK";
}String x_currency_code = "USD";
String x_type = "";if (int.Parse(permLevel) == 99)
{if (RadioButton5.Checked == true)
{x_type = "AUTH_CAPTURE";
}if (RadioButton6.Checked == true)
{x_type = "AUTH_ONLY";
}if (RadioButton7.Checked == true)
{x_type = "CAPTURE_ONLY";
}
}
else
{x_type = "AUTH_CAPTURE";
}String x_recurring_billing = "NO";
String x_bank_aba_code = txtRoutingno.Text;String x_bank_acct_num = txtAccno.Text;
String x_bank_acct_type = DropDownList1.SelectedValue;String x_bank_name = txtBankname.Text;
String x_bank_acct_name = txtNameonbankacc.Text;String x_echeck_type = "";
String x_customer_organization_type = "";if (DropDownList1.SelectedValue == "BUSINESSCHECKING")
{x_echeck_type = "CCD";
x_customer_organization_type = "B"; // business
}
else
{x_echeck_type = "WEB";
x_customer_organization_type = "I"; //individual
}
String x_card_num = txtCardno.Text;
String x_exp_date = txtExpdate.Text;String x_card_code = "";
String x_trans_id = txtorgtransid.Text;String x_auth_code = "";
String x_authentication_indicator = "";String x_cardholder_authentication_value = "";
String x_drivers_license_num = txtDriverlicenseno.Text;String x_drivers_license_state = txtDriverlicensestate.Text;
String x_drivers_license_dob = txtDriverlicenseDOB.Text;/*************************************************************
Level 2 Data
*************************************************************/String x_po_num = "";
String x_tax = "";String x_tax_exempt = "";
String x_freight = "";String x_duty = "";
//*************************************************************/**************************************************************
Optional: You can also supply merchant-defined values.
**************************************************************/String my_own_variable_name = "";
String another_field_name = "";string strInsert = "";
string cashpay = "";string nocharge = "";string billcustomer = "";
if (!CheckBox2.Checked)
{
/**************************************************************
REQUEST STRING THAT WILL BE SUBMITTED BY WAY OF
THE HTTPS POST OPERATION
**************************************************************/String strPost = "x_login=" + x_login + "&x_tran_key=" + x_tran_key + "&x_version=" + x_version + "&x_method=" + x_method;
strPost = strPost + "&x_test_request=" + x_test_request + "&x_delim_data=" + x_delim_data + "&x_delim_char=" + x_delim_char;strPost = strPost + "&x_relay_response=" + x_relay_response + "&x_first_name=" + x_first_name + "&x_last_name=" + x_last_name + "&x_company=" + x_company + "&x_address=" + x_address;
strPost = strPost + "&x_city=" + x_city + "&x_state=" + x_state + "&x_zip=" + x_zip + "&x_country=" + x_country + "&x_phone=" + x_phone + "&x_fax=" + x_fax;strPost = strPost + "&x_cust_id=" + x_cust_id + "&x_customer_ip=" + x_customer_ip + "&x_customer_tax_id=" + x_customer_tax_id + "&x_email=" + x_email;
strPost = strPost + "&x_email_customer=" + x_email_customer + "&x_merchant_email=" + x_merchant_email + "&x_invoice_num=" + x_invoice_num + "&x_description=" + x_description;strPost = strPost + "&x_ship_to_first_name=" + x_ship_to_first_name + "&x_ship_to_last_name=" + x_ship_to_last_name + "&x_ship_to_company=" + x_ship_to_company;
strPost = strPost + "&x_ship_to_address=" + x_ship_to_address + "&x_ship_to_city=" + x_ship_to_city + "&x_ship_to_state=" + x_ship_to_state;strPost = strPost + "&x_ship_to_zip=" + x_ship_to_zip + "&x_ship_to_country=" + x_ship_to_country + "&x_amount=" + x_amount;
strPost = strPost + "&x_currency_code=" + x_currency_code + "&x_method=" + x_method + "&x_type=" + x_type + "&x_recurring_billing=" + x_recurring_billing;strPost = strPost + "&x_bank_aba_code=" + x_bank_aba_code + "&x_bank_acct_num=" + x_bank_acct_num + "&x_bank_acct_type=" + x_bank_acct_type;
strPost = strPost + "&x_bank_name=" + x_bank_name + "&x_bank_acct_name=" + x_bank_acct_name + "&x_echeck_type=" + x_echeck_type + "&x_card_num=" + x_card_num;strPost = strPost + "&x_exp_date=" + x_exp_date + "&x_card_code=" + x_card_code + "&x_trans_id=" + x_trans_id + "&x_auth_code=" + x_auth_code;
strPost = strPost + "&x_authentication_indicator=" + x_authentication_indicator + "&x_cardholder_authentication_value=" + x_cardholder_authentication_value;strPost = strPost + "&x_customer_organization_type=" + x_customer_organization_type + "&x_drivers_license_num=" + x_drivers_license_num;
strPost = strPost + "&x_drivers_license_state=" + x_drivers_license_state + "&x_drivers_license_dob=" + x_drivers_license_dob + "&my_own_variable_name=" + my_own_variable_name;strPost = strPost + "&another_field_name=" + another_field_name + "&x_po_num=" + x_po_num + "&x_tax=" + x_tax + "&x_tax_exempt=" + x_tax_exempt; strPost = strPost + "&x_freight=" + x_freight + "&x_duty=" + x_duty + "&x_customer_organization_type=" + x_customer_organization_type;
//Response.Write(strPost);
//Response.End();String result = ""; StreamWriter myWriter = null;
// HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("https://test.authorize.net/gateway/transact.dll");HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("https://secure.authorize.net/gateway/transact.dll");objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;objRequest.ContentType = "application/x-www-form-urlencoded";
try
{myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
myWriter.Close();
}HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}string[] strname = new string[1000];
strname = result.Split("|".ToCharArray());if (strname[0].ToString() == "2")
{Response.Write("Your Transaction Was Denied!" + "<br>");
}if (strname[0].ToString() == "3")
{Response.Write("Error Submitting Transaction" + "<br>");
}if (strname[0].ToString() == "1")
{
// Response.Write("Your Transaction Was Approved!" + "<br>");string cardno = "";
string accno = "";if (x_card_num != "")
{int intcardLen = x_card_num.Length;
cardno = x_card_num.Substring(intcardLen - 4, 4);
}
else
{cardno = "";
}if (x_bank_acct_num != "")
{int intLen = x_bank_acct_num.Length;
accno = x_bank_acct_num.Substring(intLen - 4, 4);
}
else
{accno = "";
}
if (CheckBox2.Checked)
{cashpay = "1";
}
else
{cashpay = "0";
}
if (CheckBox3.Checked)
{nocharge = "1";
}
else
{nocharge = "0";
}
if (CheckBox4.Checked)
{billcustomer = "1";
}
else
{billcustomer = "0";
}strInsert = "Insert into transactions(franchiseid,transdate,transowner,transamount,transPaymentMethod,transCardNumber,transExpirationDate,transRoutingNumber,transAccountNumber,transBankName,transNameOnBankAccount,transBankAccountType,transDispatchNumber,transDescription,transBillingFirstName,transBillingLastName,";
strInsert = strInsert + "transBillingCompany,transBillingAddress,transBillingCity,transBillingState,transBillingZip,transBillingCountry,transBillingPhone,transBillingFax,transBillingEmail,transShippingFirstName,transShippingLastName,transShippingAddress,transShippingCity,transShippingState,transShippingZip,transShippingCountry,transCashpayment,transNocharge,transBillcustomer,transtimeinn,transtimeout)";strInsert = strInsert + "values (" + Session["franchiseid"] + ",'" + DateTime.Now.ToString() + "','" + Session["username"].ToString().Replace("'", "''") + "','" + strname[9].ToString() + "','" + x_method + "','" + "************" + cardno + "','" + x_exp_date + "','" + x_bank_aba_code + "','" + "*****" + x_bank_acct_num + "','" + x_bank_name.Replace("'", "''") + "','" + x_bank_acct_name.Replace("'", "''") + "','" + x_bank_acct_type + "','" + x_invoice_num + "','" + x_description.Replace("'", "''") + "','" + x_first_name.Replace("'", "''") + "','" + x_last_name.Replace("'", "''") + "','" + x_company.Replace("'", "''") + "','" + x_address.Replace("'", "''") + "','" + x_city.Replace("'", "''") + "','" + x_state + "','" + x_zip + "','" + x_country + "','" + x_phone + "','" + x_fax + "','" + x_email + "','" + x_ship_to_first_name.Replace("'", "''") + "','" + x_ship_to_last_name.Replace("'", "''") + "','" + x_ship_to_address.Replace("'", "''") + "','" + x_ship_to_city.Replace("'", "''") + "','" + x_ship_to_state + "','" + x_ship_to_zip + "','" + x_ship_to_country + "'," + cashpay + "," + nocharge + "," + billcustomer + ",'" + ddlTimein.SelectedValue + "','" + ddlTimeout.SelectedValue + "')";
}
}
else
{if (CheckBox2.Checked)
{cashpay = "1";
}
else
{cashpay = "0";
}
if (CheckBox3.Checked)
{nocharge = "1";
}
else
{nocharge = "0";
}
if (CheckBox4.Checked)
{billcustomer = "1";
}
else
{billcustomer = "0";
}strInsert = "Insert into transactions(franchiseid,transdate,transowner,transamount,transPaymentMethod,transCardNumber,transExpirationDate,transRoutingNumber,transAccountNumber,transBankName,transNameOnBankAccount,transBankAccountType,transDispatchNumber,transDescription,transBillingFirstName,transBillingLastName,";
strInsert = strInsert + "transBillingCompany,transBillingAddress,transBillingCity,transBillingState,transBillingZip,transBillingCountry,transBillingPhone,transBillingFax,transBillingEmail,transShippingFirstName,transShippingLastName,transShippingAddress,transShippingCity,transShippingState,transShippingZip,transShippingCountry,transCashpayment,transNocharge,transBillcustomer,transtimeinn,transtimeout)";strInsert = strInsert + "values (" + Session["franchiseid"] + ",'" + DateTime.Now.ToString() + "','" + Session["username"].ToString().Replace("'", "''") + "','" + amtVal.Text + "','','','','','','','','','" + x_invoice_num + "','" + x_description.Replace("'", "''") + "','" + x_first_name.Replace("'", "''") + "','" + x_last_name.Replace("'", "''") + "','" + x_company.Replace("'", "''") + "','" + x_address.Replace("'", "''") + "','" + x_city.Replace("'", "''") + "','" + x_state + "','" + x_zip + "','" + x_country + "','" + x_phone + "','" + x_fax + "','" + x_email + "','" + x_ship_to_first_name.Replace("'", "''") + "','" + x_ship_to_last_name.Replace("'", "''") + "','" + x_ship_to_address.Replace("'", "''") + "','" + x_ship_to_city.Replace("'", "''") + "','" + x_ship_to_state + "','" + x_ship_to_zip + "','" + x_ship_to_country + "'," + cashpay + "," + nocharge + "," + billcustomer + ",'" + ddlTimein.SelectedValue + "','" + ddlTimeout.SelectedValue + "')";
//Response.Write("<br>autho" + strInsert);
}SqlCommand cmd1 = new SqlCommand(strInsert, objConn);
objConn.Open();
cmd1.ExecuteNonQuery();
objConn.Close();Response.Redirect("Printpaymentdetails.aspx");
}protected void Button1_Click(object sender, EventArgs e)
{Response.Redirect("ABCD.aspx");
}protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{if (CheckBox2.Checked)
{pnlPaaymentMethod.Visible = false;
pnlTransact.Visible = false;pnlPaymentCCA.Visible = false;
pnlPaymentInfo.Visible = false;amount.Visible = true;
}
else
{pnlPaaymentMethod.Visible = true;
pnlTransact.Visible = true;pnlPaymentInfo.Visible = true;
pnlCardifo.Visible = true;amount.Visible = false;
}
}
}
Here is the error iam getting
server Error in '/' Application. ----------------ExecuteNonQuery: CommandText property has not been initialized Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: ExecuteNonQuery: CommandText property has not been initializedSource Error: Line 431: SqlCommand cmd1 = new SqlCommand(strInsert,objConn);Line 432: objConn.Open();Line 433: cmd1.ExecuteNonQuery();Line 434: objConn.Close();Line 435: Source File: d:Websitesserviceinfo.comsecurePaymentprocessing.aspx.cs Line: 433 Stack Trace: [InvalidOperationException: ExecuteNonQuery: CommandText property hasnot been initialized] System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async) +873524 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +72 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135 Paymentprocessing.btnSubmit_Click(Object sender, EventArgs e) in d:Websitesxyassss.aspx.cs:433 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102 ----------------Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
View 2 Replies
View Related
Jan 18, 2008
Hello,
I try to execute the following SP in my class below. But get a runtime error saying
"the connection string property has not been initialized" line 11
I have set permissions on the SP to public/execute
What is wrong here. My connection string also is below
thanks
Ehi
1 public class signup_data_entry
2 {
3 public signup_data_entry()
4 {
5 SqlConnection con = new SqlConnection("cellulant_ConnectionString");
6
7
8 SqlCommand command = new SqlCommand("Cellulant_Users_registration", con);
9 command.CommandType = CommandType.StoredProcedure;
10
11 con.Open();
<connectionStrings> <add name="cellulant_ConnectionString" connectionString="Data Source=1NEWDAYSQLEXPRESS;Initial Catalog=cellulant;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>
View 14 Replies
View Related
Apr 23, 2008
I'm writing my first vb.net app. Have a default page that uses a persons network login to query a database to get all their timekeeper id, firstname, last name, etc. But I keep getting this error. (My code is below) What am I missing???
ExecuteReader: Connection property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: ExecuteReader: Connection property has not been initialized.Source Error:
Line 21: conn.Open()
Line 22:
Line 23: reader = comm.ExecuteReader()
Line 24: If reader.Read() Then
Line 25: EmployeesLabel.Text = reader.Item("tkinit")
<script runat="server">Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)Dim conn As SqlConnectionDim comm As SqlCommandDim reader As SqlDataReaderDim connectionString As String = ConfigurationManager.ConnectionStrings("xxxConnectionString").ConnectionStringcomm = New SqlCommand("Select top 1 tkinit, tklast, tkfirst +' '+ tklast as fullname from txxx WHERE login = @login)", conn)comm.Parameters.Add("@Login", Data.SqlDbType.VarChar)comm.Parameters("@Login").Value = Me.User.Identity.Name.Substring(User.Identity.Name.IndexOf("") + 1)conn = New SqlConnection(connectionString)conn.Open()reader = comm.ExecuteReader()If reader.Read() ThenEmployeesLabel.Text = reader.Item("tkinit")FirstLastName.Text = reader.Item("fullname")End Ifreader.Close()conn.Close()End Sub</script>
View 1 Replies
View Related
May 15, 2008
Hi,
I wrote the code below to store images on SQL Server 2005; however, I keep getting this error: The connection String property has not been initialized! My Connection String is stored in the web.config and am using ASP.NET 3.5.
1 using System;
2 using System.Configuration;
3 using System.Data;
4 using System.Web;
5 using System.Web.UI;
6 using System.Web.UI.HtmlControls;
7 using System.Web.UI.WebControls;
8 using System.IO;
9 using System.Data.SqlClient;
10 using System.Web.SessionState;
11
12 public partial class CarImage : System.Web.UI.Page
13 {
14 protected void Page_Load(object sender, EventArgs e)
15 {
16 }
17
18 protected void UploadButton_Click(object sender, EventArgs e)
19 {
20 if (Page.IsValid)
21 {
22 Stream imgStream = UploadImage.PostedFile.InputStream;
23 int imgLen = UploadImage.PostedFile.ContentLength;
24
25 byte[] imgBinaryData = new byte[imgLen];
26 int n = imgStream.Read(imgBinaryData, 0, imgLen);
27
28 String StrCarID = Request.QueryString["CarID"];
29 int CarID = System.Convert.ToInt32(StrCarID);
30
31 int RowsAffected = SaveToDB(imgBinaryData, CarID);
32 if (RowsAffected > 0)
33 {
34 Response.Write("<BR>The Image was saved");
35 }
36 else
37 {
38 Response.Write("<BR>An error occurred uploading the image");
39 }
40 }
41 }
42
43 private int SaveToDB(byte[] imgBin, int carID)
44 {
45 //Store Conn String in Web.Config
46 SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["LocalSqlServer"]);
47 SqlCommand command = new SqlCommand("INSERT INTO tblImage (CarID, Image) Values (@carID, @imgBin)", connection);
48
49 SqlParameter param0 = new SqlParameter("@imgBin", SqlDbType.Image);
50 param0.Value = imgBin;
51 command.Parameters.Add(param0);
52
53 SqlParameter param1 = new SqlParameter("@carID", SqlDbType.Int, 4);
54 param1.Value = carID;
55 command.Parameters.Add(param1);
56
57 connection.Open();
58 int numRowsAffected = command.ExecuteNonQuery();
59 connection.Close();
60
61 return numRowsAffected;
62 }
63 }
Any help will be very much appreciated.E
View 11 Replies
View Related
Feb 9, 2005
I am trying to create a web form that will be used to create new users. The
first step that I am taking is creating a web form that can check the
username against a database to see if it already exists. I would it to do
this on the fly, if possible. When I execute my current code, I get the
following error:
ExecuteNonQuery: Connection property has not been initialized
Below is the code from the page itself:
-----
<!-- #INCLUDE FILE="../include/context.inc" -->
<!-- #INCLUDE FILE="../include/db_access.inc" -->
<script language="VB" runat="server">
Sub CheckButton_Click(Sender as Object, e as EventArgs)
Dim result As Int32
Dim cmd As OdbcCommand
cmd = new OdbcCommand( "(? = CALL CheckUserExists(?))", db_conn )
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add( "result", OdbcType.Int ).Direction =
ParameterDirection.ReturnValue
cmd.Parameters.Add( "@userName", OdbcType.VarChar, 100 ).Value =
Request.Form("userName")
cmd.ExecuteNonQuery()
result = cmd.Parameters("result").Value
If result <> 1 Then
CheckResults.Text="<font color=""#ff0000"">Username already
exists!</font>"
Else
CheckResults.Text="<font color=""#009900"">Username is
available.</font>"
End If
end Sub
</script>
<html><body>
<form runat="server">
<asp:TextBox id=userName runat="server" />
<asp:Button id=CheckButton runat="server" Text="Check Username"
onClick="CheckButton_Click" />
<p>
<asp:Label id=CheckResults runat=server />
</form>
</body></html>
-----
Can anyone see why I might get this error? Here are some more details of
the error:
Line 15: cmd.Parameters.Add( "@userName", OdbcType.VarChar, 100 ).Value =
Request.Form("userName")
Line 16:
*Line 17: cmd.ExecuteNonQuery()
Line 18: result = cmd.Parameters("result").Value
Thank You,
Jason Williard
View 7 Replies
View Related
Mar 11, 2005
I have a web form that is generating an error and I can't seem to figure out why for the life of me. Below is the code:
Private Sub VerifyNoDuplicateEmail()
Dim conn As SqlConnection
Dim sql As String
Dim cmd As SqlCommand
Dim id As Guid
sql = "Select UserID from SDCUsers where email='{0}'"
sql = String.Format(sql, txtEmail.Text)
cmd = New SqlCommand(sql, conn)
conn = New SqlConnection(ConfigurationSettings.AppSettings("cnSDCADC.ConnectionString"))
conn.Open()
Try
'The first this we need to do here is query the database and verify
'that no one has registed with this particular e-mail address
id = cmd.ExecuteScalar()
Response.Write(id.ToString & "<BR>")
Catch
Response.Write(sql & "<BR>")
Response.Write("An error has occurred: " & Err.Description)
Finally
If Not id.ToString Is Nothing Then
'The e-mail address is already registered.
Response.Write("Your e-mail address has already been registered with this site.<BR>")
conn.Close()
_NoDuplicates = False
Else
'It's safe to add the user to the database
conn.Close()
_NoDuplicates = True
End If
End Try
End Sub
Web.Config
<appSettings>
<!-- User application and configured property settings go here.-->
<!-- Example: <add key="settingName" value="settingValue"/> -->
<add key="cnSDCADC.ConnectionString" value="workstation id=STEPHEN;packet size=4096;integrated security=SSPI;data source=SDCADC;persist security info=False;initial catalog=sdc" />
</appSettings>
Can anyone show me the error of my ways?
Thanks,
Stephen
View 4 Replies
View Related
Jan 29, 2008
Hi,
I have written a CLR Function in C#. The function works as expected except that I am trying to read data some data during the function call and get the following error:
Msg 6522, Level 16, State 1, Line 1
A .NET Framework error occurred during execution of user-defined routine or aggregate "fn_SLARemaining":
System.InvalidOperationException: ExecuteReader: Connection property has not been initialized.
System.InvalidOperationException:
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader()
at SLARemaining.SupportTimes.addSupportHours()
at SLARemaining.CalculateTimeRemaining.GetTimeRemaining(String openDate, Decimal SLADuration)
at UserDefinedFunctions.fn_SLARemaining(SqlDateTime DateFrom, SqlDateTime DateTo, SqlInt32 PriorityTime, SqlDecimal AdjustmentTime, SqlDecimal Status)
.
The main code for the function is this:
using System;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction(DataAccess = DataAccessKind.Read)]
public static SqlString fn_SLARemaining(SqlDateTime @DateFrom, SqlDateTime @DateTo, SqlInt32 @PriorityTime, SqlDecimal @AdjustmentTime, SqlDecimal @Status)
{
SLARemaining.CalculateTimeRemaining remaining;
remaining = new SLARemaining.CalculateTimeRemaining();
int duration = Convert.ToInt32(PriorityTime.ToString());
if (!DateFrom.IsNull)
{
string date = DateFrom.Value.ToShortDateString() + " " + DateFrom.Value.ToShortTimeString();
SqlString result = remaining.GetTimeRemaining(date, duration);
return result;
}
else
{
return null;
}
}
};
The function calls the following method from another class:
public string[] addSupportHours()
{
string[] supportedHours = new string[28];
SqlDataReader dr;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "xxxxxxx"; //<-- commented out for this post
using (SqlConnection cn = new SqlConnection("context connection=true;"))
{
cn.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
//do some stuff
}
cn.Close();
cn.Dispose();
}
The error message claims that the connection has not been initialized - can't work out why? Any help will be appreciated!
View 3 Replies
View Related
Jun 28, 2006
I am having trouble initializing my connection. This is the code:
Dim
DBConnPhone As New
SqlConnection(ConfigurationManager.AppSettings("DBConnPhone"))
Dim DBConnClient As New
SqlConnection(ConfigurationManager.AppSettings("DBConnClient"))
Dim Sqlcomm1 As New SqlCommand
Dim Sqlcomm2 As New SqlCommand
DBConnPhone.Open()
DBConnClient.Open()
Once I start debugging, it stops and give me the error "The ConnectionString Property was not initialized" Any suggestions?
View 4 Replies
View Related
Feb 14, 2007
Hi, After many nights without sleep I'm not seeing this? Can anyone help why I'm getting a ConnectionString Property not set error? thanks!
Dim Sconn As StringDim DBCon As New Data.SqlClient.SqlConnectionSconn = ConfigurationManager.AppSettings("LocalSqlServer")DBCon = New SqlClient.SqlConnection(Sconn)Dim cmdCommand As New Data.SqlClient.SqlCommand
'Dont forget to instantiate a connection object
cmdCommand.Connection = DBConDBCon.Open()
View 18 Replies
View Related
Mar 29, 2006
Hi guys,
I'm getting this error:System.InvalidOperationException: The ConnectionString property has not been initialized
when I'm trying to connect to an SQL database using the following code:
Dim mySelectQuery As String = "SELECT [tabl_id] FROM [myTable]"Dim myConnection As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("myConnString"))Dim myCommand As New SqlCommand(mySelectQuery, myConnection)myConnection.Open()Dim myReader As SqlDataReadermyReader = myCommand.ExecuteReader()While myReader.Read() Response.Write(myReader("tabl_id") & "<br/>")End WhilemyConnection.Close()
and in web.config:
<appSettings/> <connectionStrings> <add name="myConnString" connectionString="Data Source=100.100.100.100;Initial Catalog=myDatabase;User ID=me;Password=password" providerName="System.Data.SqlClient"/> </connectionStrings>
If I place the actual connection string inside instead of trying to reference the web.config setting it works, but using 'System.Configuration.ConfigurationManager.AppSettings' returns the error. Is there something I'm doing wrong?
View 2 Replies
View Related
Sep 11, 2007
Hi,
i have inherited a SSIS project that was left unfinished by a previous developer. One thing i notice with it is that all the flat file sources in the connection manager have hardcoded paths for the ConnectionString property. I would like to change this so that at least the path, and if possible the file name, are dynamic - i.e. they are determined either by parameters passed into the package when it is run or they are contained within a config file.
Is this possible? Can anyone supply a link to an article or tutorial specifically covering this?
Many thanks
View 3 Replies
View Related
Apr 10, 2007
Hello! I'm recieving an error when I submit a form to an Access database. I took this site over from someone else and kept their code as I'm more of a designer than a programmer. If anyone has any ideas as to how to fix it, I would really appreciate it. I'm pretty clueless when it comes to this. I've tried to figure it out on my own, but I seem to be failing. Any help would be great! Here's what I receive when I submit the form:
The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.OleDb.OleDbConnection.Open() +203
modern_foods.promotions_form.saveInfo(Object s, EventArgs e) +535
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292
Thank you in advance!
View 10 Replies
View Related
Mar 14, 2006
I have a package that I plan to run against about 700 databases to look for anomalies. I have several package variables in place that are passed in at runtime. One of them will hold the path and filename of the error log for the current database in process. I want each database to generate it's own error log for documentation and research purposes. However, when I run the package, it continues to use the path and filename that I entered when I created the File Connection Manager. I am trying to update that value in a Script Task by using the ConnectionManager class and setting the value for the "ConnectionString" property. This method is working for the OLEDB Connection Manager (which tells the package which Access database to process), but not for my File Connection Manager. Please help!
DO
View 3 Replies
View Related
Jan 12, 2004
Im going completly nuts trying to do this. In ASP it would have taken me seconds.
Ok I think this is right but correct me if im wrong
I have a class that for example has a function that gets all the states from the DB:
File called Class.vb
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Configuration
Public Class Getalldata
Public Function GetPicdata() As SqlDataReader
Dim cnn As New SqlConnection(ConfigurationSettings.AppSettings("CONNECTION_STRING_USER"))
Dim cmd As New SqlCommand("Get_states", cnn)
cnn.Open()
Dim result As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
cnn.Close()
End Function
End Class
Ok How in the hell do I call this just to LOOP and print them out????
Sort of like this
Call class/object/whatever. I dont know how
Then
While Whaever
Loops thru the states response.writting them
Loop
Please hel;p before I completly go nuts
View 1 Replies
View Related
Aug 30, 2004
Alright- I plugged this code in to tell my form to write to SQLServer when I click the Submit button. However I error out when I load the form:
dim Conn as new OleDbConnection("DSN=MyDB")
Sub On_Click(obj as object, e as EventArgs)
dim params(3) as String
dim strSQL as String
strSQL="INSERT INTO tblSCRequest "(strRequestor, dtRequestDate, strAudience) VALUES (" & _
"'" & params(0) & "'," & _
"'" & params(1) & "'," & _
"'" & params(2) & "'")
ExecuteStatement(strSQL)
end sub
function ExecuteStatement(strSQL)
dim objCmd as new OleDbCommand(strSQL, Conn)
try
objCmd.Connection.Open()
objCmd.ExecuteNonquery()
catch ex as Exception
end try
objCmd.Connection.Close()
end function
I get this error:
C:InetpubwwwrootSOSCommCommWeb4.aspx(14) : error BC30471: Expression is not an array or a method, and cannot have an argument list.
strSQL="INSERT INTO tblSCRequest "(strRequestor, dtRequestDate, strAudience) VALUES (" & _
~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:InetpubwwwrootSOSCommCommWeb4.aspx(14) : error BC30205: End of statement expected.
strSQL="INSERT INTO tblSCRequest "(strRequestor, dtRequestDate, strAudience) VALUES (" & _
~~~~~~~~~~~~~
C:InetpubwwwrootSOSCommCommWeb4.aspx(15) : error BC30035: Syntax error.
"'" & params(0) & "'," & _
Any ideas??
View 5 Replies
View Related
Aug 1, 2006
I been all over this forum trying to find out how to get the aspnetdb.mdf running on my remote site and its driving me nuts.
i been using VWD 2005 express Edition and SQL Express
Error Server Error in '/' Application.
An attempt to attach an auto-named database for file I:DataWebqsh.eumarker_93618920-db3b-4a04-a274-3fb613afc5dfwwwApp_Dataaspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
over the last week it has been a nightmare trying to get anything working on the site but i have got all the other databases working but i can get the aspnetdb.mdf working. i am very new to ASP.net so please use the he kiss method "Keep It Simple, Stupid!" as im a newbe to this and it will just go over my head.
Thanks
View 3 Replies
View Related
Apr 17, 2006
Hi all, quick, hopefully simple question that has been driving me nuts for 3 days. Using Visual Studio 2005, doing a web app, connecting to an SQL server with already existing login names and passwords...
I have a login name and password text box and a login button. Upon clicking, sqldatasource1 checks to see if the items in the text box match a login and password in the DB. If so, it sets Profile.login and Profile.password to the values in that text box so I can use it to key off the DB for application IDs associated with that login/pass later.
It displays just the login name in a details view upon a match. If nothing is there that matches, it shows a hidden label saying "login failed".
My problem is, that I really don't want the detailsview to display if there is a match. I want it to automatically go to page2.aspx...but I can't figure this out. Response.Redirect("page2.aspx"); doesn't work. It's like the check is happening before detailsview1 shows any data and therefore it doesn't load page2....and I can't figure out how to get it to check detailsview1 for data AFTER it has been displayed.
I guess that I don't know how to get this thing to check if there is something in the detailsview, to go to page 2. It's just not working. Any help would be great! (BTW, not using the builtin login control because I can't figure out how to get that to connect to our sql database's login table.)
Thanks all!
View 7 Replies
View Related
Apr 2, 2004
I have two different SQL server installations (7 and 2000) that I have configured for using the SP_processmail procedure. Both servers can properly execute xp_startmail, xp_stopmail, xp_readmail, and xp_findnextmsg. HOWEVER, both have different problems with SP_processmail.
Using this command (and a host of many other variations):
sp_processmail @filetype = 'CSV', @separator = ',', @dbuse = 'ryantest', @set_user = 'guest'
SQL 7.0 says: Server: Msg 18007, Level 16, State 1, Line 0
Supplied datatype for @set_user is not allowed, expecting 'varchar'
I have tried every variation possible, including not specifying the yser which should result in it defaulting to the "guest" account. The message is always the same.
SQL 2000 says: Server: Msg 18025, Level 16, State 1, Line 0
xp_sendmail: failed with mail error 0x80004005
Queries processed: 0.
I have checked all my configurations and read every KB article - I can't find anything wrong.
Can someone PLEASE respond if you have any experience with SP_PROCESSMAIL on your servers.
Thanks in advance.
Ryan Hunt
View 1 Replies
View Related
Jul 20, 2005
The business rule is, the sales manager is commissioned on the avg. numberof appointments set up per salesrep per day during the month.I have 2 tables: The UserLog table records only 1 entry per day per user(salesrep). This will log how many salesreps worked a particular day. Thesecond table logs any appointments set up.UserLog: ID, UserName, EnteredTimeAppointment: ApptID, EnteredTime, ApptDateI figured that, for a given date ranged, I could1. sum the number of appointments2. sum the number of days worked2. sum the salesreps / number of days = avg number of salesreps per day3. number of appointments / avg number of salesreps per day = avg numberof appointments per sales repBut this logic is flawed. If I average out every day and then take anaverage of this daily average, I get a different result. Any ideas on howto best solve this problem?Thanks.
View 7 Replies
View Related
Jul 20, 2005
Hi -I hope some one can help me with this.I am using sql server 2000[Microsoft SQL Server 2000 - 8.00.818 (Intel X86) May 31 200316:08:15 Copyright (c) 1988-2003 Microsoft Corporation EnterpriseEdition on Windows NT 5.0 (Build 2195: Service Pack 4)]I have a stored procedure that is using cursors and a few joins, andwrites to a few tables. (I can post the code if that will help) Thestored procedure takes approximately 27 seconds to complete whenexecuted inside query analyser. However, if I run the stored proceduresource directly inside query analyser (like a long sql script), ittakes only 3 seconds!! These results are consistent and reproducible.I would think a stored procedure stores the plan, and I would expectbetter optimization. Why am I witnessing the opposite behaviour? Anyone has any experience?The server is manned by DBAs (I work at a large corporation), so Ibelieve it is well configured. We have noticed similar behaviour ondata restores on a different physical server.Thanks in advance,-praty77
View 6 Replies
View Related