Search Results

Search found 57 results on 3 pages for 'mysqlconnection'.

Page 1/3 | 1 2 3  | Next Page >

  • MySqlConnection really not close

    - by stighy
    Hi guys, i've a huge problem. Take a look to this sample code private sub FUNCTION1() dim conn as new mysqlconnection(myconnstring) conn.open ---- do something FUNCTION2() ---- conn.close end sub private sub FUNCTION2() dim conn as new mysqlconnection(myconnstring) .... conn.open -- do something conn.close end sub Despite i close regulary all my connection, they remains "open" on the mysql server. I know this because i'm using MySQL Administration tool to check how many connection i open "line by line" of my source code. In fact i get a lot of time "user has exceeded the 'max_user_connections' resource (current value: 5)" My hoster permit ONLY 5 connection, but i think that if i write GOOD source code, this cannot be a problem. So my question is: why that "damn" connections remain open ?? Thank you in advance!

    Read the article

  • Can't connect to MySql database from server using Devart

    - by annelie
    Hello, I'm having trouble connecting to a MySql database from a server. I'm using Devart to connect, and I'm not sure if I need to do something more than to simply reference the dlls. When I started working on this project it was referencing the CoreLabs dlls, which if I've understood is the previous name for Devart. That didn't work, so I downloaded the new Devart dlls instead. It works on my local machine, but when uploading to the server it crashes. I made a tiny console app to test the connection, and it fails when initialising, before I've even assigned a host etc. Do I need to do anything more than just upload my .exe file to the server? using System; using System.Collections.Generic; using System.Linq; using System.Text; using Devart.Data; using Devart.Data.MySql; namespace TestDatabaseConnection { public class Program { public static void Main(string[] args) { Console.WriteLine("about to connect"); ConnectToDatabase(); Console.ReadLine(); } public static void ConnectToDatabase() { MySqlConnection connection = new MySqlConnection(); } } } UPDATE: I can't see what the error is, I had a try catch around MySqlConnection connection = new MySqlConnection(); but no exception is thrown, it just crashes. Thanks, Annelie

    Read the article

  • Login - check database if user exists... (c#)

    - by SAMIR BHOGAYTA
    I have managed to do the following... string connectionString = "datasource=localhost;username=xxx;password=xxx;database=xxx"; MySqlConnection mySqlConnection = new MySqlConnection(connectionString); string selectString = "SELECT username, password " + "FROM forum_members " + "WHERE username = '" + frmUsername.Text + "' AND password = '" + frmPassword.Text + "'"; MySqlCommand mySqlCommand = new MySqlCommand(selectString, mySqlConnection); mySqlConnection.Open(); String strResult = String.Empty; strResult = (String)mySqlCommand.ExecuteScalar(); mySqlConnection.Close(); if (strResult.Length == 0) { Label1.Text = "INCORRECT USER/PASS!" //could redirect to register page } else { Label1.Text = "YOU ARE LOGGED IN!"; //set loggin in sessions variables }

    Read the article

  • Connecting to hosted MySQL server with Java

    - by Infiniti Fizz
    Hi, I've been recently trying to connect to a hosted MySQL using Java but can't get it to work. I can connect to a local MySQL with localhost using: connect = DriverManager.getConnection("jdbc:mysql://localhost/lego?" + "user=******&password=*******"); (Replacing the astrisks withmy username and password) I can connect to the hosted MySQL database fine with PHP using: mysql_connect('mysql.hosts.co.uk','******','**********'); mysql_select_db('test'); My problem is, I cannot connect via Java. I have an Exception which is caught if the connection doesn't work and this is always printed out. Any ideas why it isn't working? Am I doing something wrong? Thanks for your time, InfinitiFizz

    Read the article

  • remote database connection with my iphone application using cocos2d

    - by Rana
    MCPResult *theResult; MCPConnection *mySQLConnection; //initialize connection string vars NSString *dbURL = @"192.168.0.16"; NSString *userName = @""; NSString *pass = @""; int port = 3306; //open connection to database mySQLConnection = [[MCPConnection alloc] initToHost: dbURL withLogin:userName password:pass usingPort:port]; if ([mySQLConnection isConnected]) { NSLog(@"The connection to database was successfull"); } else { NSLog(@"The connection to database was failed"); } //selection to database if([mySQLConnection selectDB:@"blackjack_DB"]) { NSLog(@"Database found"); } else { NSLog(@"Database not found"); } //selection to Table theResult = [mySQLConnection queryString:@"select * from test"]; //theResult = [mySQLConnection queryString:@"select * from test where id='1'"]; //theResult = [mySQLConnection queryString:@"select id from test"]; //theResult = [mySQLConnection queryString:@"select name from test where pass='main_pass'"]; NSArray *m= [theResult fetchRowAsArray]; NSLog(@"%@", m); NSLog(@"%@", [m objectAtIndex:2]); Use this code for connecting & receive information from remotedatabase. And also use some framework. AppKit.framework, Cocoa.framework, Carbon.framework, MCPKit_bundled.framework. But stile i didn't connect my application with remort database.

    Read the article

  • What is the best way to handle the Connections to MySql from c#

    - by srk
    I am working on a c# application which connects to MySql server. There are about 20 functions which will connect to database. This application will be deployed in 200 over machines. I am using the below code to connect to my database which is identical for all the functions. The problem is, i can some connections were not closed and still alive when deployed in 200 over machines. Connection String : <add key="Con_Admin" value="server=test-dbserver; database=test_admindb; uid=admin; password=1Password; Use Procedure Bodies=false;" /> Declaration of the connection string Globally in application [Global.cs] : public static MySqlConnection myConn_Instructor = new MySqlConnection(ConfigurationSettings.AppSettings["Con_Admin"]); Function to query database : public static DataSet CheckLogin_Instructor(string UserName, string Password) { DataSet dsValue = new DataSet(); //MySqlConnection myConn = new MySqlConnection(ConfigurationSettings.AppSettings["Con_Admin"]); try { string Query = "SELECT accounts.str_nric AS Nric, accounts.str_password AS `Password`," + " FROM accounts " + " WHERE accounts.str_nric = '" + UserName + "' AND accounts.str_password = '" + Password + "\'"; MySqlCommand cmd = new MySqlCommand(Query, Global.myConn_Instructor); MySqlDataAdapter da = new MySqlDataAdapter(); if (Global.myConn_Instructor.State == ConnectionState.Closed) { Global.myConn_Instructor.Open(); } cmd.ExecuteScalar(); da.SelectCommand = cmd; da.Fill(dsValue); Global.myConn_Instructor.Close(); } catch (Exception ex) { Global.myConn_Instructor.Close(); ExceptionHandler.writeToLogFile(System.Environment.NewLine + "Target : " + ex.TargetSite.ToString() + System.Environment.NewLine + "Message : " + ex.Message.ToString() + System.Environment.NewLine + "Stack : " + ex.StackTrace.ToString()); } return dsValue; }

    Read the article

  • how to serialize a DataTable to json or xml

    - by loviji
    Hello, i'm trying to serialize DataTable to Json or XML. is it possibly and how? any tutorials and ideas, please. For example a have a sql table: CREATE TABLE [dbo].[dictTable]( [keyValue] [int] IDENTITY(1,1) NOT NULL, [valueValue] [int] NULL, CONSTRAINT [Psd2Id] PRIMARY KEY CLUSTERED ( [keyValue] ASC )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] C# code: string connectionString = "server=localhost;database=dbd;uid=**;pwd=**"; SqlConnection mySqlConnection = new SqlConnection(connectionString); string selectString = "SELECT keyValue, valueValue FROM dicTable"; SqlCommand mySqlCommand = mySqlConnection.CreateCommand(); mySqlCommand.CommandText = selectString; SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(); mySqlDataAdapter.SelectCommand = mySqlCommand; DataSet myDataSet = new DataSet(); mySqlConnection.Open(); string dataTableName = "dictionary"; mySqlDataAdapter.Fill(myDataSet, dataTableName); DataTable myDataTable = myDataSet.Tables[dataTableName]; //now how to serialize it?

    Read the article

  • datalist edit mode.

    - by Ranjana
    i have a datalist control <ItemTemplate> <tr> <td height="31px"> <asp:Label ID="lblStudentName" runat="server" Text="StudentName :" Font-Bold="true"></asp:Label> <%# DataBinder.Eval(Container.DataItem, "StudentName") %> </td> <td height="31px"> <asp:LinkButton ID="lnkEdit" runat="server" CommandName="edit">Edit</asp:LinkButton> </td> </tr> <tr> <td> <asp:Label ID="lblAdmissionNo" runat="server" Text="AdmissionNo :" Font-Bold="true"></asp:Label> <%# DataBinder.Eval(Container.DataItem, "AdmissionNo")%> </td> </tr> <tr> <td height="31px"> <asp:Label ID="lblStudentRollNo" runat="server" Text="StdentRollNo :" Font-Bold="true"></asp:Label> <%# DataBinder.Eval(Container.DataItem, "StdentRollNo") %> </td> <td height="31px"> <asp:LinkButton ID="lnkEditroll" runat="server" CommandName="edit">Edit</asp:LinkButton> </td> </tr> </ItemTemplate> <EditItemTemplate> <tr> <td height="31px"> <asp:Label ID="lblStudentName" runat="server" Text="StudentName :" Font-Bold="true"></asp:Label> <asp:TextBox ID="txtProductName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "StudentName") %>'></asp:TextBox> </td> <td> <asp:LinkButton ID="lnkUpdate" runat="server" CommandName="update">Update</asp:LinkButton> <asp:LinkButton ID="lnkCancel" runat="server" CommandName="cancel">Cancel</asp:LinkButton> </td> </tr> <tr> <td height="31px"> <asp:Label ID="lblAdmissionNo" runat="server" Text="AdmissionNo :" Font-Bold="true"></asp:Label> <%# DataBinder.Eval(Container.DataItem, "AdmissionNo")%> </td> </tr> <tr> <td height="31px"> <asp:Label ID="lblStudentRollNo" runat="server" Text="StudentRollNo :" Font-Bold="true"></asp:Label> <asp:TextBox ID="txtStudentRollNo" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "StdentRollNo") %>'></asp:TextBox> </td> <td> <asp:LinkButton ID="LinkButton1" runat="server" CommandName="update">Update</asp:LinkButton> <asp:LinkButton ID="LinkButton2" runat="server" CommandName="cancel">Cancel</asp:LinkButton> </td> </tr> </EditItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:DataList> code behind: protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DataTable dt = new DataTable(); dt = obj.GetSamples(); DataList1.DataSource = dt; DataList1.DataBind(); } } public void DataBind() { DataTable dt = new DataTable(); dt = obj.GetSamples(); DataList1.DataSource = dt; DataList1.DataBind(); } protected void DataList1_EditCommand1(object source, DataListCommandEventArgs e) { DataList1.EditItemIndex = e.Item.ItemIndex; DataBind(); } protected void DataList1_CancelCommand1(object source, DataListCommandEventArgs e) { DataList1.EditItemIndex = -1; DataBind(); } protected void DataList1_UpdateCommand1(object source, DataListCommandEventArgs e) { // Get the DataKey value associated with current Item Index. // int AdmissionNo = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex]); string AdmissionNo = DataList1.DataKeys[e.Item.ItemIndex].ToString(); // Get updated value entered by user in textbox control for // ProductName field. TextBox txtProductName; txtProductName = (TextBox)e.Item.FindControl("txtProductName"); TextBox txtStudentRollNo; txtStudentRollNo = (TextBox)e.Item.FindControl("txtStudentRollNo"); // string variable to store the connection string // retrieved from the connectionStrings section of web.config string connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString; // sql connection object SqlConnection mySqlConnection = new SqlConnection(connectionString); // sql command object initialized with update command text SqlCommand mySqlCommand = new SqlCommand("update SchoolAdmissionForm set StudentName=@studentname ,StdentRollNo=@studentroll where AdmissionNo=@admissionno", mySqlConnection); mySqlCommand.Parameters.Add("@studentname", SqlDbType.VarChar).Value = txtProductName.Text; mySqlCommand.Parameters.Add("@admissionno", SqlDbType.VarChar).Value = AdmissionNo; mySqlCommand.Parameters.Add("@studentroll", SqlDbType.VarChar).Value = txtStudentRollNo.Text; // check the connection state and open it accordingly. if (mySqlConnection.State == ConnectionState.Closed) mySqlConnection.Open(); // execute sql update query mySqlCommand.ExecuteNonQuery(); // check the connection state and close it accordingly. if (mySqlConnection.State == ConnectionState.Open) mySqlConnection.Close(); // reset the DataList mode back to its initial state DataList1.EditItemIndex = -1; DataBind(); // BindDataList(); } But it works fine.... but when i click edit command both the Fields 1.StudentName 2.StudentRollNo im getting textboxes to all the fields where i placed textbox when i click 'edit' command and not the particular field alone . but i should get oly the textbox visible to the field to which i clik as 'edit' , and the rest remain same without showing textboxes even though it is in editmode

    Read the article

  • C# ApplicationContext usage

    - by rd42
    Apologies if my terminology is off, I'm new to C#. I'm trying to use an ApplicationContext file to store mysql conn values, like dbname, username, password. The class with mysql conn string is "using" the namespace for the ApplicationContext, but when I print out the connection string, the values are making it. A friend said, "I'm not initializing it" but couldn't stay to expand on what "it" was. and the "Console.WriteLine("1");" in ApplicationContext.cs never shows up. Do I need to create an ApplicationContext object and the call Initialize() on that object? Thanks for any help. ApplicationContext.cs: namespace NewApplication.Context { class ApplicationContext { public static string serverName; public static string username; public static string password; public static void Initialize() { //need to read through config here try { Console.WriteLine("1"); XmlDocument xDoc = new XmlDocument(); xDoc.Load(".\\Settings.xml"); XmlNodeList serverNodeList = xDoc.GetElementsByTagName("DatabaseServer"); XmlNodeList usernameNodeList = xDoc.GetElementsByTagName("UserName"); XmlNodeList passwordNodeList = xDoc.GetElementsByTagName("Password"); } catch (Exception ex) { // MessageBox.Show(ex.ToString()); //TODO: Future write to log file username = "user"; password = "password"; serverName = "localhost"; } } } } MySQLManager.cs: note: dbname is the same as the username as you'll see in the code, I copied this from a friend who does that. using System; using System.Collections.Generic; using System.Linq; using System.Text; using MySql.Data; using MySql.Data.MySqlClient; using NewApplication.Context; namespace NewApplication.DAO { class MySQLManager { private static MySqlConnection conn; public static MySqlConnection getConnection() { if (conn == null || conn.State == System.Data.ConnectionState.Closed) { string connStr = "server=" + ApplicationContext.serverName + ";user=" + ApplicationContext.username + ";database=" + ApplicationContext.username + ";port=3306;password=" + ApplicationContext.password + ";"; conn = new MySqlConnection(connStr); try { Console.WriteLine("Connecting to MySQL... "); Console.WriteLine("Connection string: " + connStr + "\n"); conn.Open(); // Perform databse operations // conn.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } return conn; } } } and, thanks for still reading, this is the code that uses the two previous files: class LogDAO { MySqlConnection conn; public LogDAO() { conn = MySQLManager.getConnection(); } Thank you, rd42

    Read the article

  • ASP.NET Membership ChangePassword control - Need to check for previous password

    - by Steve
    Hi guys, I have a new table that hold old passwords, I need to check if there is a match. If there is a match I need the ChangePassword contol to NOT change the password. I need to tell the user that this password was used and pic a new one. I can't seem to be able to interrupt the control from changing the password. Maybe I am using the wrong event. Here is a piece of my code, or how I wish it would work. I appreciate all your help. protected void ChangePassword1_ChangedPassword(object sender, EventArgs e) { MembershipUser user = Membership.GetUser(); string usrName = ""; if (user != null) { string connStr = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString; SqlConnection mySqlConnection = new SqlConnection(connStr); SqlCommand mySqlCommand = mySqlConnection.CreateCommand(); mySqlCommand.CommandText = "Select UserName from OldPasswords where UserName = 'test'"; mySqlConnection.Open(); SqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader(CommandBehavior.Default); while (mySqlDataReader.Read()) { usrName = mySqlDataReader["UserName"].ToString(); if (usrName == user.ToString()) { Label1.Text = "Match"; } else { Label1.Text = "NO Match!"; } }

    Read the article

  • ASP.Net GridView UpdatePanel Paging Gives Error On Second Click

    - by joe
    I'm trying to implement a GridView with paging inside a UpdatePanel. Everything works great when I do my first click. The paging kicks in and the next set of data is loaded quickly. However, when I then try to click a link for another page of data, I get the following error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 12030 aspx code <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <contenttemplate> <asp:GridView ID="GridView1" runat="server" CellPadding="2" AllowPaging="true" AllowSorting="true" PageSize="20" OnPageIndexChanging="GridView1_PageIndexChanging" OnSorting="GridView1_PageSorting" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="ActivityLogID" HeaderText="Activity Log ID" SortExpression="ActivityLogID" /> <asp:BoundField DataField="ActivityDate" HeaderText="Activity Date" SortExpression="ActivityDate" /> <asp:BoundField DataField="ntUserID" HeaderText="NTUserID" SortExpression="ntUserID" /> <asp:BoundField DataField="ActivityStatus" HeaderText="Activity Status" SortExpression="ActivityStatus" /> </Columns> </asp:GridView> </contenttemplate> </asp:UpdatePanel> code behind private void bindGridView(string sortExp, string sortDir) { SqlCommand mySqlCommand = new SqlCommand(sSQL, mySQLconnection); SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlCommand); mySqlAdapter.Fill(dtDataTable); DataView myDataView = new DataView(); myDataView = dt.DefaultView; if (sortExp != string.Empty) { myDataView.Sort = string.Format("{0} {1}", sortExp, sortDir); } GridView1.DataSource = myDataView; GridView1.DataBind(); if (mySQLconnection.State == ConnectionState.Open) { mySQLconnection.Close(); } } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; bindGridView(); } protected void GridView1_PageSorting(object sender, GridViewSortEventArgs e) { bindGridView(e.SortExpression, sortOrder); } any clues on what is causing the error on the second click?

    Read the article

  • Visual Studio 2010 Hosting :: Connect to MySQL Database from Visual Studio VS2010

    - by mbridge
    So, in order to connect to a MySql database from VS2010 you need to 1. download the latest version of the MySql Connector/NET from http://www.mysql.com/downloads/connector/net/ 2. install the connector (if you have an older version you need to remove it from Control Panel -> Add / Remove Programs) 3. open Visual Studio 2010 4. open Server Explorer Window (View -> Server Explorer) 5. use Connect to Database button 6. in the Choose Data Source windows select MySql Database and press Continue 7. in the Add Connection window - set server name: 127.0.0.1 or localhost for MySql server running on local machine or an IP address for a remote server - username and password - if the the above data is correct and the connection can be made, you have the possibility to select the database If you want to connect to a MySql database from a C# application (Windows or Web) you can use the next sequence: //define the connection reference and initialize it MySql.Data.MySqlClient.MySqlConnection msqlConnection = null; msqlConnection = new MySql.Data.MySqlClient.MySqlConnection(“server=localhost;user id=UserName;Password=UserPassword;database=DatabaseName;persist security info=False”);     //define the command reference MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();     //define the connection used by the command object msqlCommand.Connection = this.msqlConnection;     //define the command text msqlCommand.CommandText = "SELECT * FROM TestTable;"; try {     //open the connection     this.msqlConnection.Open();     //use a DataReader to process each record     MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();     while (msqlReader.Read())     {         //do something with each record     } } catch (Exception er) {     //do something with the exception } finally {     //always close the connection     this.msqlConnection.Close(); }.

    Read the article

  • Fatal error encountered during command execution with a mySQL INSERT

    - by Brian
    I am trying to execute a INSERT statement on a mySQL DB in C#: MySqlConnection connection = new MySqlConnection("SERVER=" + _dbConnection + ";" + "DATABASE=" + _dbName + ";" + "PORT=" + _dbPort + ";" + "UID=" + _dbUsername + ";" + "PASSWORD=" + _dbPassword + ";"); MySqlDataAdapter adapter; DataSet dataset = new DataSet(); command = new MySqlCommand(); command.Connection = connection; command.CommandText = "INSERT INTO plugins (pluginName, enabled) VALUES (@plugin,@enabled)"; command.Parameters.AddWithValue("@name", "pluginName"); command.Parameters.AddWithValue("@enabled", false); adapter = new MySqlDataAdapter(command); adapter.Fill(dataset); The plugin table consists of two columns: pluginName(varchar(50)) and enabled(boolean). This fails with the error: mysql Fatal error encountered during command execution. Any ideas on why this would fail?

    Read the article

  • how to solve this Problem in asp.net crystal report.

    - by Ayyappan.Anbalagan
    Problem in crystal report After excecuting the bellow code,In my report page it ask like "The report you requested requires further information" server= user= password= databse= protected void Page_Load(object sender, EventArgs e) { MySqlConnection sqlcom = new MySqlConnection("server=localhost;userid=root;password=root;database=hemaepdb;"); MySqlCommand cmd = new MySqlCommand("SP_ViewBillDetails", sqlcom); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("p_Invoice_Id", MySqlDbType.Int16).Value = 1; cmd.Parameters.Add("p_Org_id", MySqlDbType.Int16).Value = 1; MySqlDataAdapter adapter = new MySqlDataAdapter(cmd); DataSet dsTest = new DataSet(); sqlcom.Open(); adapter.Fill(dsTest, "Table"); sqlcom.Close(); CrystalReportViewer1.Visible = true; ReportDocument myRpt = new ReportDocument(); myRpt.Load(Server.MapPath("CrystalReport.rpt")); myRpt.SetDatabaseLogon("root", "root", "localhost", "hemaepdb"); myRpt.SetDataSource(dsTest); CrystalReportViewer1.ReportSource = myRpt; }

    Read the article

  • Creating a loop that will edit 60 TextBox names?

    - by Darkmage
    text box set1 = 1 to 30 = in the query name = br1id to br30id textbox set 2 = 1 to 30 = in the result output i dont understand how to create a loop based on 30 diffrent textbox names? i cant copy paste these lines 30 times editing the textbox names, that wold just look wrong. try { MySqlConnection mysqlCon = new MySqlConnection( "server= 195.159.253.229;" + "Database = bruker;" + "user id=bobby;" + "password=LoLOW###;"); MySqlCommand cmd1 = new MySqlCommand( "SELECT brukernavn From bruker where ID = '" + br1id.Text + "';", mysqlCon); mysqlCon.Open(); navX[0] = cmd1.ExecuteScalar().ToString(); br1txt3.Text = navX[0]; }

    Read the article

  • C# mysqlreader on same connection error

    - by dominiquel
    Hi, I must find a way to do this in C#, if possible... I must loop on my folder list (mysql table), and for each folder I instanciate I must do another query, but when I do this it says : "There is already an open DataReader associated with this Connection" and I am inside a mysqlreader loop already. Note that I have oversimplified the code just to show you, the fact is that I must do queries inside a mysqlreader loop, and it looks to be impossible as they are on the same connection? MySqlConnection cnx = new MySqlConnection(connexionString); cnx.Open(); MySqlCommand command= new MySqlCommand("SELECT * FROM folder WHERE folder_id = " + id, cnx); MySqlDataReader reader= commande.ExecuteReader(); while (reader.Read()) { this.folderList[this.folderList.Length] = new CFolder(reader.GetInt32"folder_id"), cnx); } reader.Close(); cnx.Close();

    Read the article

  • What does MySqlDataAdapter.Fill return when the results are empty?

    - by Brian
    I have a 'worker' function that will be processing any and all sql queries in my program. I will need to execute queries that return result sets and ones that just execute stored procedures without any results. Is this possible with MySqlDataAdapter.Fill or do I need to use the MySqlCommand.ExecuteNonQuery() method? Here is my 'worker' function for reference: private DataSet RunQuery(string SQL) { MySqlConnection connection; MySqlCommand command; MySqlDataAdapter adapter; DataSet dataset = new DataSet(); lock(locker) { connection = new MySqlConnection(MyConString); command = new MySqlCommand(); command = connection.CreateCommand(); command.CommandText = SQL; adapter = new MySqlDataAdapter(); adapter.Fill(dataset); } return dataset; }

    Read the article

  • [C# n MySQL] Creating a database using Connector/NET Programming?

    - by yeeen
    How to create a database using connector/net programming? How come the following doesn't work? string connStr = "server=localhost;user=root;port=3306;password=mysql;"; MySqlConnection conn = new MySqlConnection(connStr); MySqlCommand cmd; string s0; try { conn.Open(); s0 = "CREATE DATABASE IF NOT EXISTS `hello`;"; cmd = new MySqlCommand(s0, conn); conn.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); }

    Read the article

  • Can I indicate where my MySQL parameter should go more meaningfully than just having a ? to mark the

    - by Paul H
    I've got a chunk of code where I can pass info into a MySQL command using parameters through an ODBC connection. Example code showing surname passed in using string surnameToLookFor: using (OdbcConnection DbConn = new OdbcConnection( connectToDB )) { OdbcDataAdapter cmd = new OdbcDataAdapter( "SELECT Firstname, Address, Postcode FROM customers WHERE Surname = ?", DbConn); OdbcParameter odbcParam = new OdbcParameter("surname", surnameToLookFor); cmd.SelectCommand.Parameters.Add(odbcParam); cmd.Fill(dsCustomers, "customers"); } What I'd like to know is whether I can indicate where my parameter should go more meaningfully than just having a ? to mark the position - as I could see this getting quite hard to debug if there are multiple parameters being replaced. I'd like to provide a name to the parameter in a manner something like this: SELECT Firstname, Address, Postcode FROM customers WHERE Surname = ?surname ", When I try this it just chokes. The following code public System.Data.DataSet Customer_Open(string sConnString, long ld) { using (MySqlConnection oConn = new MySqlConnection(sConnString)) { oConn.Open(); MySqlCommand oCommand = oConn.CreateCommand(); oCommand.CommandText = "select * from cust_customer where id=?id"; MySqlParameter oParam = oCommand.Parameters.Add("?id", MySqlDbType.Int32); oParam.Value = ld; oCommand.Connection = oConn; DataSet oDataSet = new DataSet(); MySqlDataAdapter oAdapter = new MySqlDataAdapter(); oAdapter.SelectCommand = oCommand; oAdapter.Fill(oDataSet); oConn.Close(); return oDataSet; } } is from http://www.programmingado.net/a-389/MySQL-NET-parameters-in-query.aspx and includes the fragment where id=?id Which would be ideal. Is this only available through the .Net connector rather than the ODBC? If it is possible to do using ODBC how would I need to change my code fragment to enable this?

    Read the article

  • ASP.Net Forms authentication provider issue

    - by George2
    Hello everyone, I am using VSTS 2008 + .Net 3.5 + ASP.Net to develop a simple web application. And I am using Forms authentication for my web site (I use command aspnet_regsql.exe to create a new database in SQL Server 2008 Enterprise to host database for Forms Authentication. I am not using SQL Server Express.). I am learning Forms authentication from here, http://msdn.microsoft.com/en-us/library/ff648345.aspx#paght000022_usingthesqlmembershipprovider my question is for the name of membership defaultProvider, the value must be "SqlProvider"? Or I can use any arbitrary name, for example like this (I replace the value "SqlProvider" to "MyTestSqlProvider")? <connectionStrings> <add name="MySqlConnection" connectionString="Data Source=MySqlServer;Initial Catalog=aspnetdb;Integrated Security=SSPI;" /> </connectionStrings> <system.web> ... <membership defaultProvider="MyTestSqlProvider" userIsOnlineTimeWindow="15"> <providers> <clear /> <add name="MyTestSqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MySqlConnection" applicationName="MyApplication" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" /> </providers> </membership> thanks in advance, George

    Read the article

  • C#/.Net Error: MySql.Data Object reference not set to an instance of an object.

    - by Simon
    Hello, I get this exception on my Windows 7 64bit in application running in VS 2008 express. I am using Connector/Net 6.2.2.0: Message: Object reference not set to an instance of an object. Source: MySql.Data in MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId) Stack trace: in MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId) in MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId) in MySql.Data.MySqlClient.MySqlDataReader.NextResult() in MySql.Data.MySqlClient.MySqlDataReader.Close() in MySql.Data.MySqlClient.MySqlConnection.Close() in MySql.Data.MySqlClient.MySqlConnection.Dispose(Boolean disposing) in System.ComponentModel.Component.Finalize() No inner exception. This exception is unhalted and the debugger dont point on any code line. It just say "Object reference not set to an instance of an object. MySql.Data" This error is really hard to repeat. On my Windows XP 32bit is all ok. Could it be error in 64bit Windows 7? Thank you very much for your answers. Regards, simon

    Read the article

  • MySQL Connector: parameters not being added

    - by LookitsPuck
    Hey all! Looking at my query log for MySQL, I see my parameters aren't being added. Here's my code: MySqlConnection conn = new MySqlConnection(ApplicationVariables.ConnectionString()); MySqlCommand com = new MySqlCommand(); try { conn.Open(); com.Connection = conn; com.CommandText = String.Format(@"SELECT COUNT(*) AS totalViews FROM pr_postreleaseviewslog AS prvl WHERE prvl.dateCreated BETWEEN (@startDate) AND (@endDate) AND prvl.postreleaseID IN ({0})" , ids); com.CommandType = CommandType.Text; com.Parameters.Add(new MySqlParameter("@startDate", thisCampaign.Startdate)); com.Parameters.Add(new MySqlParameter("@endDate", endDate)); numViews = Convert.ToInt32(com.ExecuteScalar()); } catch (Exception ex) { } finally { conn.Dispose(); com.Dispose(); } Looking at the query log, I see this: SELECT COUNT(*) AS totalViews FROM pr_postreleaseviewslog AS prvl WHERE prvl.dateCreated BETWEEN (@startDate) AND (@endDate) AND prvl.postreleaseID IN (1,2) I've used the MySQL .NET connector on countless projects (I actually have a base class that takes care of opening these connections, and closing them with transactions, etc.). However, I took over this application, and here I am now. Thanks for the help!

    Read the article

  • Why is F# member not found when used in subclass

    - by James Black
    I have a base type that I want to inherit from, for all my DAO objects, but this member gets the error further down about not being defined: type BaseDAO() = member v.ExecNonQuery2(conn)(sqlStr) = let comm = new MySqlCommand(sqlStr, conn, CommandTimeout = 10) comm.ExecuteNonQuery |> ignore comm.Dispose |> ignore I inherit in this type: type CreateDatabase() = inherit BaseDAO() member private self.createDatabase(conn) = self.ExecNonQuery2 conn "DROP DATABASE IF EXISTS restaurant" This is what I see when my script runs in the interactive shell: --> Referenced 'C:\Program Files\MySQL\MySQL Connector Net 6.2.3\Assemblies\MySql.Data.dll' [Loading C:\Users\jblack\Documents\Visual Studio 2010\Projects\RestaurantService\RestaurantDAO\BaseDAO.fs] namespace FSI_0106.RestaurantServiceDAO type BaseDAO = class new : unit -> BaseDAO member ExecNonQuery2 : conn:MySql.Data.MySqlClient.MySqlConnection -> sqlStr:string -> unit member execNonQuery : sqlStr:string -> unit member execQuery : sqlStr:string * selectFunc:(MySql.Data.MySqlClient.MySqlDataReader -> 'a list) -> 'a list member f : x:obj -> string member Conn : MySql.Data.MySqlClient.MySqlConnection end [Loading C:\Users\jblack\Documents\Visual Studio 2010\Projects\RestaurantService\RestaurantDAO\CreateDatabase.fs] C:\Users\jblack\Documents\Visual Studio 2010\Projects\RestaurantService\RestaurantDAO\CreateDatabase.fs(56,14): error FS0039: The field, constructor or member 'ExecNonQuery2' is not defined I am curious what I am doing wrong. I have tried not inheriting, and just instantiating the BaseDAO type in the function, but I get the same error. I started on this path because I had a property that had the same error, so it seems there may be a problem with how I am defining my BaseDAO type, but it compiles with no error, which further confuses me about this problem.

    Read the article

  • C# web service, MySql encoding problem

    - by Boban
    I use C# web service to insert, delete and get data from MySql database. The problem is some of the data is in Macedonian (Cyrilic). When I insert directly in the database, it inserts ok. For example: "???" is "???". When I insert throgh the service, it's not. For example: "???" is "???". When I try to get data throug the service, it gets it ok. What's the problem with the inserting? Here is part of my code for inserting: MySqlConnection connection = new MySqlConnection(MyConString); MySqlCommand command = connection.CreateCommand(); command.CommandText = "INSERT INTO user (id_user, name VALUES (NULL, ?name);"; command.Parameters.Add("?name", MySqlDbType.VarChar).Value = name; connection.Open(); command.ExecuteReader(); connection.Close(); return thisrow; Tnq U in advance!!!

    Read the article

  • Help with use of .NET Generics/Dictionary in replacing my Arrays

    - by Rollo R
    Hello, I have these code: Mypage.cs string[] strParameterName = new string[2] {"?FirstName", "?LastName"}; string[] strParameterValue = new string[2] {"Josef", "Stalin"}; MyConnection.MySqlLink(strConnection, strCommand, strParameterName, strParameterValue, dtTable); Myclass.cs public static void MySqlLink(string strConnection, string strCommand, string[] strParameterName, string[] strParameterValue, DataTable dtTable) { dtTable.Clear(); MySqlConnection MyConnection = new MySqlConnection(strConnection); MySqlCommand MyCommand = new MySqlCommand(strCommand, MyConnection); for (int i = 0; i < strParameterName.Length; i++) { MyCommand.Parameters.AddWithValue(strParameterName[i].ToString(), strParameterValue[i].ToString()); } MySqlDataAdapter MyDataAdapter = new MySqlDataAdapter(MyCommand); MyDataAdapter.Fill(dtTable); } And then my Sql Command will be something like "SELECT * FROM MyTable WHERE FirstName=?FirstName AND LastName=?LastName" As you can see, I am using arrays for the Parameter Name and Parameter Value and they both have to "match" with each other and ofcourse the Sql Command. Someone recommended to me that I use .NET "Dictionary" instead of arrays. Now I have never used that before. Can someone show me a relative example of how I am to use .NET Dictionary here?

    Read the article

1 2 3  | Next Page >