|
I am having some problems calling stored functions from my c# code, sometimes it works and sometimes it doesn't. When it doesnt I get an error message
"parameter '?9' not found in the collection"
I dont have a parameter with the name '9' in the function I am trying to call! it does it when I call some functions but not others. Another function I call it says it can't find parameter '?50' again I don't have such a parameter
Anyone got any ideas? I have a feeling I'm missing something obvious
///
/// This method executes a stored function
///
/// <param name="functionName" />Name of the function
/// <param name="parameters" />A list of parameters to be passed into the function
/// <returns>The result of the function
public object executeFunction(string functionName, List<parameter> parameters)
{
//this is the variable that will contain the return value from the function
DbParameter returnParam = factory.CreateParameter();
try
{
conn.Open(); //open the connection
//start a transaction
DbTransaction trans;
trans = conn.BeginTransaction();
DbCommand command = factory.CreateCommand(); //create a command
command.Transaction = trans; //set the transaction for the command
command.CommandText = functionName; //set the command text to the name if the function
command.Connection = conn; //set the commands connection
command.CommandType = CommandType.StoredProcedure; //set the type to stored procedure
//add each of the input parameters to the command
foreach (Parameter a in parameters)
{
DbParameter param = factory.CreateParameter();
param.ParameterName = a.name;
param.Value = a.value;
command.Parameters.Add(param);
}
//initialise the return parameter and add it to the command
returnParam.ParameterName = "?rv";
command.Parameters.Add(returnParam);
returnParam.Direction = ParameterDirection.ReturnValue;
command.ExecuteNonQuery(); //execute the function
trans.Commit(); //finish the transaction
conn.Close(); //close the connection
}
catch (Exception ex)
{
throw new Exception("the following exception was thrown: \n" + ex.Message + "\n\nyou probably have an error in your parameters");
}
finally
{
conn.Close();
}
return returnParam.Value; //return the result
}
|
|
|
|
|
Well ... without showing your SQL-statement I can't help you ... and I think the error states that the parameter number 9 is missing!
|
|
|
|
|
That was my initial thought too (and I have double checked I am parring the correct parameters) however I have another function that gives me the error message "parameter '?50' not found in collection" where there are far less than 50 parameters.
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Businesslayer;
namespace GUI
{
public partial class GUI : Form
{
public GUI()
{
InitializeComponent();
}
private void GUI_Load(object sender, EventArgs e)
{
}
private void btnCreate_Click(object sender, EventArgs e)
{
// con();
createDatabase(showDetails());
}
public string showDetails()
{
string nameDatabase = dateTimePicker1.Value.ToString("MMdd");
string nameDB = "CustList_PGE_" + nameDatabase;
MessageBox.Show("The name of the database will be CustList_PGE_" + nameDatabase);
string nameTable = dateTimePicker1.Value.ToString("MMddyy");
string nameTB = "CustList_PGE" + nameTable;
MessageBox.Show("The name of the Table will be CustList_PGE" + nameTable);
return nameDB;
}
public void con()
{
Businesslayer.Businesslayer newobj = new Businesslayer.Businesslayer();
//newobj.createObject();
}
public void createDatabase(string dbName)
{
Businesslayer.Businesslayer createObj = new Businesslayer.Businesslayer();
createObj.createDatabase(dbName);
}
}
}------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace Businesslayer
{
public class Businesslayer
{
//public void createObject()
//{
// Datalayer.Datalayer obj = new Datalayer.Datalayer();
//}
public void createDatabase(string databaseName)
{
Datalayer.Datalayer createObj = new Datalayer.Datalayer();
createObj.createDatabase(databaseName);
}
}
}
-------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace Datalayer
{
public class Datalayer
{
SqlConnection conObj;
public void conSql()
{
try
{
conObj = new SqlConnection();
conObj.ConnectionString = "Data Source=TSPL-DEV07;Initial Catalog=PGEImport;Integrated Security=True";
if (conObj.State == ConnectionState.Closed)
{
conObj.Open();
}
}
catch
{
}
}
public void createDatabase(string nameDB)
{
try
{
conSql();
SqlCommand cmdObj = new SqlCommand();
cmdObj.Connection = conObj;
cmdObj.CommandText = "CreateDataBases";
cmdObj.CommandType = System.Data.CommandType.StoredProcedure;
cmdObj.Parameters.AddWithValue("@databaseName", nameDB);
cmdObj.Parameters.AddWithValue("@databaseName_Log", nameDB + "CustList_PGE_0131_log");
cmdObj.Parameters.AddWithValue("@mdfName",@"C:\mssql\data");
cmdObj.Parameters.AddWithValue("@ldfName",@"C:\mssql\data");
cmdObj.ExecuteNonQuery();
}
catch(Exception ex)
{
//The error 5 is an "access denied" error.
//You may need to use an admin account to actually change the security on the file such that the sql server process can open it.
}
finally
{
if (conObj.State == ConnectionState.Open)
{
conObj.Close();
}
}
}
}
}
|
|
|
|
|
Seems rather obvious, the account you are trying run the stored proc under doesn't have the necessary rights and permissions to create databases.
only two letters away from being an asset
|
|
|
|
|
Hi,
In my application i am using threads and socket programming to ping a mobile application
I want to set the timeout value for the Socket.send message
for this i have used socket.sendtimeout= value;
but the same socket is used for asynchronous communication ....so as i have set the socket.sendtimeout value its effecting the asynchronous communication..
My aim is to Set the Timeout value only for the pinging message such that communication must not get effected,,,,( I want to set the timeout period for a particular Ping 'send' only ....) If any one knows this then Please Do Let Me Know
its me sid
|
|
|
|
|
Hi,
FYI: you can perfcrm a ping to an IP address using the Ping Class, which exists
in .NET since 2.0; not in CF, so it would have to be the mobile that is being pinged.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I have 3 forms say, Form1 , Form2 and Form3 . Form1 contains a ListView control which is populated through a collection instance say Collection1 . After doing an operation, I need to update the ListView present in the Form1 from Form3 . Form3 is displayed from Form2.
I am looking for a best method to do this. Following are the points which I have in my mind to implement this.
1 - Make the Collection1 instance as static (Singleton) and add some events to that class. Hook event handlers from the Form1 . So when new items are added to this collection in Form3 , events get fired and Form1's ListView will get updated. Some kind of MVC pattern.
2 - Pass the Form1 object through the constructors to Form2 and to Form3 .
Which one do you suggest ? Or is there any other efficient method to do this ?
|
|
|
|
|
I would suggest that you implement something like the Model View Controller pattern or the Observer pattern instead. Trust me on this - it's a much more robust design method.
|
|
|
|
|
Pete O'Hanlon wrote: I would suggest that you implement something like the Model View Controller pattern or the Observer pattern instead
So will my method 1 falls under observer, right ?
|
|
|
|
|
It depends on what else you are trying to do with the view - but in the case specified above, then yes - it's the observer pattern.
|
|
|
|
|
Pete O'Hanlon wrote: It depends on what else you are trying to do with the view
As I mentioned, view contains a ListView which shows the collection entries. It's not doing anything else.
Pete O'Hanlon wrote: but in the case specified above, then yes - it's the observer pattern.
Thanks. This confused me about observer and MVC. How about saying this as MVC ? Think my model as the Collection1. When it is updated, respective view's are getting updated. So is it possible to categorize this into MVC too ?
|
|
|
|
|
It is - both patterns work around similar areas. MVC is a more complex pattern, but it does more.
|
|
|
|
|
Thanks for helping me Pete.
|
|
|
|
|
|
Hello , Please Help Me
I make a component but i can't change icon on tools bar and when i make event for component and i never use it, my project have problem, if i use default event ??????
|
|
|
|
|
What does this mean ? Post some code so we can try to work out what you're talking about. Also, what does 'my project have problem' mean ? Does it crash ? Does it run slow ? Does it not get invited to parties ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: Does it not get invited to parties ?
Don't be flippant CG. It looks like an urgent question to me.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
*grin* He did say 'urgent', so I guess it must be.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
How I can Make my program read or write to the USB.
|
|
|
|
|
What exactly do you want to do ? To talk to a device on USB, you need a driver for that device, then you'd code to a common interface, such as the print or TWAIN interface. To copy files, you can work out which drives are detachable, although you can't work out for sure that they are USB.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Yes I wnt to talk to a device connected to USB.
I am designing it(radio scanner) .
So the question how to make a driver.
For more specific.How to write assembly cod eto the driver using C# instructions
|
|
|
|
|
You can't write a device driver in C#, AFAIK. You need to use C or C++.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
How can i list (Web Application List) of share point in remote server by using share point web service or without using webservice
|
|
|
|