Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Ad icon
Sell your Land, House on idamata.lk for FREE
sajith.xp.pk
Updated:
Thursday at 9:03 AM
Handmade Character Soft Toys
anil1961
Updated:
Tuesday at 2:11 PM
Bodim.lk out now !
Manoj Suranga Bandara
Updated:
Sunday at 3:05 AM
Power Lifting Lever Belt
SkullVamp
Updated:
Jun 13, 2026
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Jun 13, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
How to Connect C# with remote mysql database
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="isurutmv" data-source="post: 23373983" data-attributes="member: 470006"><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">C# walin karapu application ekaka database eka thiyenne cpanel eke mata one mage application eka cpanel eke database ekath ekka connect karanna man mage connection eke code eka thama me</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">[CODE]</span></p><p><span style="font-size: 18px">private string databaseName = string.Empty;</span></p><p><span style="font-size: 18px"> public string DatabaseName</span></p><p><span style="font-size: 18px"> {</span></p><p><span style="font-size: 18px"> get { return databaseName; }</span></p><p><span style="font-size: 18px"> set { databaseName = value; }</span></p><p><span style="font-size: 18px"> }</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"> public string Password { get; set; }</span></p><p><span style="font-size: 18px"> private MySqlConnection connection = null;</span></p><p><span style="font-size: 18px"> public MySqlConnection Connection</span></p><p><span style="font-size: 18px"> {</span></p><p><span style="font-size: 18px"> get { return connection; }</span></p><p><span style="font-size: 18px"> }</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"> private static DbConnection _instance = null;</span></p><p><span style="font-size: 18px"> public static DbConnection Instance()</span></p><p><span style="font-size: 18px"> {</span></p><p><span style="font-size: 18px"> if (_instance == null)</span></p><p><span style="font-size: 18px"> _instance = new DbConnection();</span></p><p><span style="font-size: 18px"> return _instance;</span></p><p><span style="font-size: 18px"> }</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"> public bool IsConnect()</span></p><p><span style="font-size: 18px"> {</span></p><p><span style="font-size: 18px"> if (Connection == null)</span></p><p><span style="font-size: 18px"> {</span></p><p><span style="font-size: 18px"> if (String.IsNullOrEmpty(databaseName))</span></p><p><span style="font-size: 18px"> return false;</span></p><p><span style="font-size: 18px"> string connstring = string.Format("Server=xx.xxx.xxx.xxx;database={0}; UID=xxxxx; password=xxxxxx;SslMode = none", databaseName);</span></p><p><span style="font-size: 18px"> connection = new MySqlConnection(connstring);</span></p><p><span style="font-size: 18px"> </span></p><p><span style="font-size: 18px"> connection.Open();</span></p><p><span style="font-size: 18px"> }</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"> return true;</span></p><p><span style="font-size: 18px"> }</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"> public void Close()</span></p><p><span style="font-size: 18px"> {</span></p><p><span style="font-size: 18px"> connection.Close();</span></p><p><span style="font-size: 18px"> }</span></p><p><span style="font-size: 18px"> }</span></p><p><span style="font-size: 18px">[/CODE]</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">but mata me error eka enawa</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">[CODE]</span></p><p><span style="font-size: 18px">MySql.Data.MySqlClient.MySqlException was unhandled</span></p><p><span style="font-size: 18px"> Code=0</span></p><p><span style="font-size: 18px"> ErrorCode=-2147467259</span></p><p><span style="font-size: 18px"> HResult=-2147467259</span></p><p><span style="font-size: 18px"> Message=Unable to connect to any of the specified MySQL hosts.</span></p><p><span style="font-size: 18px"> Number=1042</span></p><p><span style="font-size: 18px"> Source=MySql.Data</span></p><p><span style="font-size: 18px"> StackTrace:</span></p><p><span style="font-size: 18px"> at MySql.Data.MySqlClient.NativeDriver.Open()</span></p><p><span style="font-size: 18px"> at MySql.Data.MySqlClient.Driver.Open()</span></p><p><span style="font-size: 18px"> at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)</span></p><p><span style="font-size: 18px"> at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()</span></p><p><span style="font-size: 18px"> at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()</span></p><p><span style="font-size: 18px"> at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()</span></p><p><span style="font-size: 18px"> at MySql.Data.MySqlClient.MySqlPool.GetConnection()</span></p><p><span style="font-size: 18px"> at MySql.Data.MySqlClient.MySqlConnection.Open()</span></p><p><span style="font-size: 18px"> at POS_Jayamal.DbConnection.IsConnect() in C:\Users\123456\Documents\POS_Jayamal\POS_Jayamal\DBConnection.cs:line 49</span></p><p><span style="font-size: 18px"> at POS_Jayamal.StockDetailsForm.load_items() in C:\Users\123456\Documents\POS_Jayamal\POS_Jayamal\StockDetailsForm.cs:line 23</span></p><p><span style="font-size: 18px"> at POS_Jayamal.StockDetailsForm.StockDetailsForm_Load(Object sender, EventArgs e) in C:\Users\123456\Documents\POS_Jayamal\POS_Jayamal\StockDetailsForm.cs:line 16</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.Form.OnLoad(EventArgs e)</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.Form.OnCreateControl()</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.Control.CreateControl()</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.Control.WmShowWindow(Message& m)</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.Control.WndProc(Message& m)</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.ScrollableControl.WndProc(Message& m)</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.Form.WmShowWindow(Message& m)</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.Form.WndProc(Message& m)</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)</span></p><p><span style="font-size: 18px"> at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)</span></p><p><span style="font-size: 18px"> InnerException: </span></p><p><span style="font-size: 18px"> Code=0</span></p><p><span style="font-size: 18px"> ErrorCode=-2147467259</span></p><p><span style="font-size: 18px"> HResult=-2147467259</span></p><p><span style="font-size: 18px"> Message=Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.</span></p><p><span style="font-size: 18px"> Number=0</span></p><p><span style="font-size: 18px"> Source=MySql.Data</span></p><p><span style="font-size: 18px"> StackTrace:</span></p><p><span style="font-size: 18px"> at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings)</span></p><p><span style="font-size: 18px"> at MySql.Data.Common.StreamCreator.GetStream(MySqlConnectionStringBuilder settings)</span></p><p><span style="font-size: 18px"> at MySql.Data.MySqlClient.NativeDriver.Open()</span></p><p><span style="font-size: 18px"> InnerException: </span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">[/CODE]</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Access Host ekata PC eke IP ekath deela thiyenne bn<img src="/styles/default/xenforo/smilies/default/sorry.gif" class="smilie" loading="lazy" alt=":sorry:" title="Sorry :sorry:" data-shortname=":sorry:" /><img src="/styles/default/xenforo/smilies/default/sorry.gif" class="smilie" loading="lazy" alt=":sorry:" title="Sorry :sorry:" data-shortname=":sorry:" /><img src="/styles/default/xenforo/smilies/default/sorry.gif" class="smilie" loading="lazy" alt=":sorry:" title="Sorry :sorry:" data-shortname=":sorry:" /><img src="/styles/default/xenforo/smilies/default/sorry.gif" class="smilie" loading="lazy" alt=":sorry:" title="Sorry :sorry:" data-shortname=":sorry:" /></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"></span></p></blockquote><p></p>
[QUOTE="isurutmv, post: 23373983, member: 470006"] [SIZE="5"] C# walin karapu application ekaka database eka thiyenne cpanel eke mata one mage application eka cpanel eke database ekath ekka connect karanna man mage connection eke code eka thama me [CODE] private string databaseName = string.Empty; public string DatabaseName { get { return databaseName; } set { databaseName = value; } } public string Password { get; set; } private MySqlConnection connection = null; public MySqlConnection Connection { get { return connection; } } private static DbConnection _instance = null; public static DbConnection Instance() { if (_instance == null) _instance = new DbConnection(); return _instance; } public bool IsConnect() { if (Connection == null) { if (String.IsNullOrEmpty(databaseName)) return false; string connstring = string.Format("Server=xx.xxx.xxx.xxx;database={0}; UID=xxxxx; password=xxxxxx;SslMode = none", databaseName); connection = new MySqlConnection(connstring); connection.Open(); } return true; } public void Close() { connection.Close(); } } [/CODE] but mata me error eka enawa [CODE] MySql.Data.MySqlClient.MySqlException was unhandled Code=0 ErrorCode=-2147467259 HResult=-2147467259 Message=Unable to connect to any of the specified MySQL hosts. Number=1042 Source=MySql.Data StackTrace: at MySql.Data.MySqlClient.NativeDriver.Open() at MySql.Data.MySqlClient.Driver.Open() at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() at POS_Jayamal.DbConnection.IsConnect() in C:\Users\123456\Documents\POS_Jayamal\POS_Jayamal\DBConnection.cs:line 49 at POS_Jayamal.StockDetailsForm.load_items() in C:\Users\123456\Documents\POS_Jayamal\POS_Jayamal\StockDetailsForm.cs:line 23 at POS_Jayamal.StockDetailsForm.StockDetailsForm_Load(Object sender, EventArgs e) in C:\Users\123456\Documents\POS_Jayamal\POS_Jayamal\StockDetailsForm.cs:line 16 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) InnerException: Code=0 ErrorCode=-2147467259 HResult=-2147467259 Message=Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Number=0 Source=MySql.Data StackTrace: at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings) at MySql.Data.Common.StreamCreator.GetStream(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.NativeDriver.Open() InnerException: [/CODE] Access Host ekata PC eke IP ekath deela thiyenne bn:sorry::sorry::sorry::sorry: [/SIZE] [/QUOTE]
Insert quotes…
Verification
Haya warak paha keeyada? (haya wadi kireema paha)
Post reply
Top
Bottom