Search Results

Search found 11 results on 1 pages for 'sqlparameters'.

Page 1/1 | 1 

  • SqlCommand.Dispose() not disposing the SqlParameters in it - Memory Leak - C#.NET

    - by NLV
    Hello I've a windows forms application with MS SQL Server 2005 as the back end. I have written code in the form to call few stored procedures using SqlConnection, SqlCommand objects and i properly dispose everything. I've disposed sqlcommand object by calling oSqlCommand.Dispose() But i witnessed my application consuming huge amount of memory. I basically pass large XML files as SqlParameters. I finally decided to memory profile it using RedGate Memory profiler and i noticed that the System.Data.SqlClient.SqlParameters are not disposed. Any insights on this? Thanks NLV

    Read the article

  • Is it possible to get the parsed text of a SqlCommand with SqlParameters?

    - by Burg
    What I am trying to do is create some arbitrary sql command with parameters, set the values and types of the parameters, and then return the parsed sql command - with parameters included. I will not be directly running this command against a sql database, so no connection should be necessary. So if I ran the example program below, I would hope to see the following text (or something similar): WITH SomeTable (SomeColumn) AS ( SELECT N':)' UNION ALL SELECT N'>:o' UNION ALL SELECT N'^_^' ) SELECT SomeColumn FROM SomeTable And the sample program is: using System; using System.Data; using System.Data.SqlClient; namespace DryEraseConsole { class Program { static void Main(string[] args) { const string COMMAND_TEXT = @" WITH SomeTable (SomeColumn) AS ( SELECT N':)' UNION ALL SELECT N'>:o' UNION ALL SELECT @Value ) SELECT SomeColumn FROM SomeTable "; SqlCommand cmd = new SqlCommand(COMMAND_TEXT); cmd.CommandText = COMMAND_TEXT; cmd.Parameters.Add(new SqlParameter { ParameterName = "@Value", Size = 128, SqlDbType = SqlDbType.NVarChar, Value = "^_^" }); Console.WriteLine(cmd.CommandText); Console.ReadKey(); } } } Is this something that is achievable using the .net standard libraries? Initial searching says no, but I hope I'm wrong.

    Read the article

  • SQL - .NET - SqlParameters - AddWithValue - Are there any negative performance implications when Par

    - by hamlin11
    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx I'm used to adding sql parameters to a sqlCommand using the add() function. This allows me to specify the type of the sqlParameter, but it requires another line to set the value. It's nice to use the AddWithValue function, but it skips the "specify the parameter type" step. I'm guessing this causes the parameters to be sent over as strings contained within single quotes (''), but I'm not sure. Is this the case, and does this cause significantly slower performance of the stored procedures? Note: I understand that it is nice to validate user data on the .NET side of things by specifying the data type for params -- I'm only concerned about reflection-type overhead of AddWithValue either on the .NET or SQL side.

    Read the article

  • Conversion failed: SqlParameter and DateTime

    - by Tim
    I'm changing old,vulnerable sqlcommands with SqlParameters but get a SqlException: System.Data.SqlClient.SqlException {"Conversion failed when converting datetime from character string."} on sqlCommand.ExecuteScalar() Dim sqlString As String = _ "SELECT TOP 1 " & _ "fiSL " & _ "FROM " & _ "tabData AS D " & _ "WHERE " & _ "D.SSN_Number = '@SSN_Number' " & _ "AND D.fiProductType = 1 " & _ "AND D.Repair_Completion_Date > '@Repair_Completion_Date' " & _ "ORDER BY " & _ "D.Repair_Completion_Date ASC" Dim obj As Object Dim sqlCommand As SqlCommand Try sqlCommand = New SqlCommand(sqlString, Common.MyDB.SqlConn_RM2) sqlCommand.CommandTimeout = 120 sqlCommand.Parameters.AddWithValue("@SSN_Number", myClaim.SSNNumber) sqlCommand.Parameters.AddWithValue("@Repair_Completion_Date", myClaim.RepairCompletionDate) If Common.MyDB.SqlConn_RM2.State <> System.Data.ConnectionState.Open Then Common.MyDB.SqlConn_RM2.Open() obj = sqlCommand.ExecuteScalar() Catch ex As Exception Dim debug As String = ex.ToString Finally Common.MyDB.SqlConn_RM2.Close() End Try myClaim.RepairCompletionDate is a SQLDateTime. Do i have to remove the quotes in the sqlString to compare Date columns? But then i dont get a exception but incorrect results.

    Read the article

  • How to pass XML from C# to a stored procedure in SQL Server 2008?

    - by Geetha
    I want to pass xml document to sql server stored procedure such as this: CREATE PROCEDURE BookDetails_Insert (@xml xml) I want compare some field data with other table data and if it is matching that records has to inserted in to the table. Requirements: How do I pass XML to the stored procedure? I tried this, but it doesn’t work:[Working] command.Parameters.Add( new SqlParameter("@xml", SqlDbType.Xml) { Value = new SqlXml(new XmlTextReader(xmlToSave.InnerXml, XmlNodeType.Document, null)) }); How do I access the XML data within the stored procedure? Edit: [Working] String sql = "BookDetails_Insert"; XmlDocument xmlToSave = new XmlDocument(); xmlToSave.Load("C:\\Documents and Settings\\Desktop\\XML_Report\\Books_1.xml"); SqlConnection sqlCon = new SqlConnection("..."); using (DbCommand command = sqlCon.CreateCommand()) { **command.CommandType = CommandType.StoredProcedure;** command.CommandText = sql; command.Parameters.Add( new SqlParameter("@xml", SqlDbType.Xml) { Value = new SqlXml(new XmlTextReader(xmlToSave.InnerXml , XmlNodeType.Document, null)) }); sqlCon.Open(); DbTransaction trans = sqlCon.BeginTransaction(); command.Transaction = trans; try { command.ExecuteNonQuery(); trans.Commit(); sqlCon.Close(); } catch (Exception) { trans.Rollback(); sqlCon.Close(); throw; } Edit 2: How to create a select query to select pages, description based on some conditions. <booksdetail> <isn_13>700001048</isbn_13> <isn_10>01048B</isbn_10> <Image_URL>http://www.landt.com/Books/large/00/7010000048.jpg</Image_URL> <title>QUICK AND FLUPKE</title> <Description> PRANKS AND JOKES QUICK AND FLUPKE </Description> </booksdetail>

    Read the article

  • Create SQL parameters programmatically

    - by Neo
    Another annoying one for me but probably something simple. I have a number of possible where clauses for a query based on user input, my question is how can I add these programmatically? For instance: wherequery = @"WHERE fieldname = @p_FieldName AND "; if (txtValue.textLength > 0){ wherequery += "fieldname2 = @p_FieldName2 AND "; } query = @"SELECT * FROM tabe" + wherequery; sql = connection.CreateCommand(); sql.CommandText = query; How would I go about doing the parameters for that? I've tried ArrayLists, Dictionaries and a few other methods but can't find a way of doing it. Ideally I'd want to do something like this: SqlParameter[] sqlparams; wherequery = @"WHERE fieldname = @p_FieldName AND "; if (txtValue.textLength > 0){ wherequery += "fieldname2 = @p_FieldName2 AND "; sqlparams.Parameters.Add("@p_FieldName2 ", SqlDbType.VarChar).Value = txtValue.text; } query = @"SELECT * FROM tabe" + wherequery; sql = connection.CreateCommand(); sql.CommandText = query; sql.Parameters.Add(sqlparams);

    Read the article

  • Best way to implement a data structure in PHP ?

    - by Double Gras
    Hi, I want to use some kind of data structure in PHP (5.2), mainly in order to not pollute the global namespace. I think about two approaches, using an array or a class. Could you tell me which approach is better ? Thanks $SQL_PARAMETERS = array ( 'server' => '127.0.0.1', 'login' => 'root'); class SqlParameters { const SERVER = '127.0.0.1'; const LOGIN = 'root'; } echo $SQL_PARAMETERS['server']; echo SqlParameters::SERVER;

    Read the article

  • Is it possible to rebind sql paramters using the result from a cfquery?

    - by Larry
    When I run the following code: <cfquery name="someQuery" result="queryResult" datasource="wetakepictures"> SELECT id FROM events WHERE category_id = <cfqueryparam value="1" cfsqltype="cf_sql_integer"> OR title like <cfqueryparam value="%test%" cfsqltype="cf_sql_varchar"> </cfquery> <cfoutput> #queryResult.sql# <br /> #ArrayToList(queryResult.sqlparameters)# </cfoutput> It outputs: SELECT id FROM events WHERE category_id = ? OR title like ? 1,%test% I need the actual string "SELECT id FROM events WHERE category_id = 1 OR title like '%test%'". Is there a way to rebind the parameters to the sql?

    Read the article

  • TransactionScope question - how can I keep the DTC from getting involved in this?

    - by larryq
    (I know the circumstances surrounding the DTC and promoting a transaction can be a bit mysterious to those of us not in the know, but let me show you how my company is doing things, and if you can tell me why the DTC is getting involved, and if possible, what I can do to avoid it, I'd be grateful.) I have code running on an ASP.Net webserver. We have one database, SQL 2008. Our data access code looks something like this-- We have a data access layer that uses a wrapper object for SQLConnections and SQLCommands. Typical use looks like this: void method1() { objDataObject = new DataAccessLayer(); objDataObject.Connection = SomeConnectionMethod(); SqlCommand objCommand = DataAccessUtils.CreateCommand(SomeStoredProc); //create some SqlParameters, add them to the objCommand, etc.... objDataObject.BeginTransaction(IsolationLevel.ReadCommitted); objDataObject.ExecuteNonQuery(objCommand); objDataObject.CommitTransaction(); objDataObject.CloseConnection(); } So indeed, a very thin wrapper around SqlClient, SqlConnection etc. I want to run several stored procs in a transaction, and the wrapper class doesn't allow me access to the SqlTransaction so I can't pass it from one component to the next. This led me to use a TransactionScope: using (TransactionScope tx1 = new TransactionScope(TransactionScope.RequiresNew)) { method1(); method2(); method3(); tx1.Complete(); } When I do this, the DTC gets involved, and unfortunately our webservers don't have "allow remote clients" enabled in the MSDTC settings-- getting IT to allow that will be a fight. I'd love to avoid DTC becoming involved but can I do it? Can I leave out the transactional calls in methods1-3() and just let the TransactionScope figure it all out?

    Read the article

  • Am I trying to Implement Multiple Inheritance. How can I do this.

    - by Shantanu Gupta
    I have created a class say A which has some functions defined as protected. Now Class B inherits A and class C inherits B. Class A has private default constructor and protected parameterized constructor. I want Class B to be able to access all the protected functions defined in Class A but class C can have access on some of the functions only not all the functions and class C is inheriting class B. How can I restrict access to some of the functions of Class A from Class C ? EDIT: namespace Db { public Class A { private A(){} protected A(string con){assign this value} protected DataTable getTable(){return Table;} protected Sqlparameters setParameters(){return parameter;} } } namespace Data { public Class B:A { protected B():base("constring"){} protected DataTable output(){return getTable();} protected sqlparameter values(param IDataParameter[] parameter){} } } namespace Bsns { public Class C:B { protected C():base(){} protected DataTable show() {return values(setparameter());} } } EDIT I think what I am trying to do here is Multiple inheritance. Please check. Class A { //suppose 10 functions are declared } Class B:A { //5 functions declared which are using A's function in internal body } Class C:B { //using all functions of B but require only 4 functions of A to be accessible by C. }

    Read the article

  • Trouble updating my datagrid in WPF

    - by wrigley06
    As the title indicates, I'm having trouble updating a datagrid in WPF. Basically what I'm trying to accomplish is a datagrid, that is connected to a SQL Server database, that updates automatically once a user enters information into a few textboxes and clicks a submit button. You'll notice that I have a command that joins two tables. The data from the Quote_Data table will be inserted by a different user at a later time. For now my only concern is getting the information from the textboxes and into the General_Info table, and from there into my datagrid. The code, which I'll include below compiles fine, but when I hit the submit button, nothing happens. This is the first application I've ever built working with a SQL Database so many of these concepts are new to me, which is why you'll probably look at my code and wonder what is he thinking. public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public DataSet mds; // main data set (mds) private void Window_Loaded_1(object sender, RoutedEventArgs e) { try { string connectionString = Sqtm.Properties.Settings.Default.SqtmDbConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); //Merging tables General_Info and Quote_Data SqlCommand cmd = new SqlCommand("SELECT General_Info.Quote_ID, General_Info.Open_Quote, General_Info.Customer_Name," + "General_Info.OEM_Name, General_Info.Qty, General_Info.Quote_Num, General_Info.Fab_Drawing_Num, " + "General_Info.Rfq_Num, General_Info.Rev_Num, Quote_Data.MOA, Quote_Data.MOQ, " + "Quote_Data.Markup, Quote_Data.FOB, Quote_Data.Shipping_Method, Quote_Data.Freight, " + "Quote_Data.Vendor_Price, Unit_Price, Quote_Data.Difference, Quote_Data.Vendor_NRE_ET, " + "Quote_Data.NRE, Quote_Data.ET, Quote_Data.STI_NET, Quote_Data.Mfg_Time, Quote_Data.Delivery_Time, " + "Quote_Data.Mfg_Name, Quote_Data.Mfg_Location " + "FROM General_Info INNER JOIN dbo.Quote_Data ON General_Info.Quote_ID = Quote_Data.Quote_ID", connection); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); MainGrid.ItemsSource = dt.DefaultView; mds = new DataSet(); da.Fill(mds, "General_Info"); MainGrid.DataContext = mds.Tables["General_Info"]; } } catch (Exception ex) { MessageBox.Show(ex.Message); } // renaming column names from the database so they are easier to read in the datagrid MainGrid.Columns[0].Header = "#"; MainGrid.Columns[1].Header = "Date"; MainGrid.Columns[2].Header = "Customer"; MainGrid.Columns[3].Header = "OEM"; MainGrid.Columns[4].Header = "Qty"; MainGrid.Columns[5].Header = "Quote Number"; MainGrid.Columns[6].Header = "Fab Drawing Num"; MainGrid.Columns[7].Header = "RFQ Number"; MainGrid.Columns[8].Header = "Rev Number"; MainGrid.Columns[9].Header = "MOA"; MainGrid.Columns[10].Header = "MOQ"; MainGrid.Columns[11].Header = "Markup"; MainGrid.Columns[12].Header = "FOB"; MainGrid.Columns[13].Header = "Shipping"; MainGrid.Columns[14].Header = "Freight"; MainGrid.Columns[15].Header = "Vendor Price"; MainGrid.Columns[16].Header = "Unit Price"; MainGrid.Columns[17].Header = "Difference"; MainGrid.Columns[18].Header = "Vendor NRE/ET"; MainGrid.Columns[19].Header = "NRE"; MainGrid.Columns[20].Header = "ET"; MainGrid.Columns[21].Header = "STINET"; MainGrid.Columns[22].Header = "Mfg. Time"; MainGrid.Columns[23].Header = "Delivery Time"; MainGrid.Columns[24].Header = "Manufacturer"; MainGrid.Columns[25].Header = "Mfg. Location"; } private void submitQuotebtn_Click(object sender, RoutedEventArgs e) { CustomerData newQuote = new CustomerData(); int quantity; quantity = Convert.ToInt32(quantityTxt.Text); string theDate = System.DateTime.Today.Date.ToString("d"); newQuote.OpenQuote = theDate; newQuote.CustomerName = customerNameTxt.Text; newQuote.OEMName = oemNameTxt.Text; newQuote.Qty = quantity; newQuote.QuoteNumber = quoteNumberTxt.Text; newQuote.FdNumber = fabDrawingNumberTxt.Text; newQuote.RfqNumber = rfqNumberTxt.Text; newQuote.RevNumber = revNumberTxt.Text; try { string insertConString = Sqtm.Properties.Settings.Default.SqtmDbConnectionString; using (SqlConnection insertConnection = new SqlConnection(insertConString)) { insertConnection.Open(); SqlDataAdapter adapter = new SqlDataAdapter(Sqtm.Properties.Settings.Default.SqtmDbConnectionString, insertConnection); SqlCommand updateCmd = new SqlCommand("UPDATE General_Info " + "Quote_ID = @Quote_ID, " + "Open_Quote = @Open_Quote, " + "OEM_Name = @OEM_Name, " + "Qty = @Qty, " + "Quote_Num = @Quote_Num, " + "Fab_Drawing_Num = @Fab_Drawing_Num, " + "Rfq_Num = @Rfq_Num, " + "Rev_Num = @Rev_Num " + "WHERE Quote_ID = @Quote_ID"); updateCmd.Connection = insertConnection; System.Data.SqlClient.SqlParameterCollection param = updateCmd.Parameters; // // Add new SqlParameters to the command. // param.AddWithValue("Open_Quote", newQuote.OpenQuote); param.AddWithValue("Customer_Name", newQuote.CustomerName); param.AddWithValue("OEM_Name", newQuote.OEMName); param.AddWithValue("Qty", newQuote.Qty); param.AddWithValue("Quote_Num", newQuote.QuoteNumber); param.AddWithValue("Fab_Drawing_Num", newQuote.FdNumber); param.AddWithValue("Rfq_Num", newQuote.RfqNumber); param.AddWithValue("Rev_Num", newQuote.RevNumber); adapter.UpdateCommand = updateCmd; adapter.Update(mds.Tables[0]); mds.AcceptChanges(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } Thanks in advance to anyone who can help, I really appreciate it, Andrew

    Read the article

1