473,738 Members | 7,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connection to a db

I want make a connection with MySQL (don't know why, i need, that's all
; ) ) in C#
but i don't know a lots the OleDbConnection , i have do that:

using System;
using System.Data.Ole Db;

class database
{
// OleDbConnection oConn;
// OleDbCommand oCmd;

public void setConnection()
{
OleDbConnection myConnection = new OleDbConnection (
"Provider=M ySQL ODBC 3.51 Driver;Data
Source=192.168. 1.2;Database=go lf;");
string mySelectQuery = "SELECT * FROM golfnews";

myConnection.Op en();
OleDbCommand myCommand = new OleDbCommand(my SelectQuery, myConnection);
myCommand.Comma ndTimeout = 20;
OleDbDataReader myReader;
myReader = myCommand.Execu teReader();

while (myReader.Read( ))
{
Console.WriteLi ne(myReader.ToS tring());
}
myReader.Close( );

myConnection.Cl ose();
}
}

class Prog
{
static void Main()
{
database db1 = new database();
db1.setConnecti on();
}
}

but i receive in the output a security error :

exception does not generated : System.Security .SecurityExcept ion: failure
from the request
at database.setCon nection()
at Prog.Main()

Le jeu autorisé de l'assembly défaillant était :
<PermissionSe t class="System.S ecurity.Permiss ionSet"
version="1">
<IPermission class="System.S ecurity.Permiss ions.Environmen tPermission,
mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken= b77a5c561934e08 9"
version="1"
Read="USERNAME"/>
<IPermission class="System.S ecurity.Permiss ions.FileDialog Permission,
mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken= b77a5c561934e08 9"
version="1"
Unrestricted="t rue"/>
<IPermission class="System.S ecurity.Permiss ions.FileIOPerm ission,
mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken= b77a5c561934e08 9"
version="1"
Read="J:\Prog\C #\"
PathDiscovery=" J:\Prog\C#\"/>
<IPermission
class="System.S ecurity.Permiss ions.IsolatedSt orageFilePermis sion, mscorlib,
Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9"
version="1"
Allowed="Assemb lyIsolationByUs er"
UserQuota="9223 372036854775807 "
Expiry="9223372 036854775807"
Permanent="True "/>
<IPermission class="System.S ecurity.Permiss ions.Reflection Permission,
mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken= b77a5c561934e08 9"
version="1"
Flags="Reflecti onEmit"/>
<IPermission class="System.S ecurity.Permiss ions.SecurityPe rmission,
mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken= b77a5c561934e08 9"
version="1"
Flags="Assertio n, Execution, BindingRedirect s"/>
<IPermission class="System.S ecurity.Permiss ions.UIPermissi on, mscorlib,
Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9"
version="1"
Unrestricted="t rue"/>
<IPermission class="System.N et.DnsPermissio n, System, Version=1.0.500 0.0,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9"
version="1"
Unrestricted="t rue"/>
<IPermission class="System.D rawing.Printing .PrintingPermis sion,
System.Drawing, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken= b03f5f7f11d50a3 a"
version="1"
Level="DefaultP rinting"/>
<IPermission class="System.D iagnostics.Even tLogPermission, System,
Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9"
version="1">
<Machine name="."
access="Instrum ent"/>
</IPermission>
<IPermission class="System.S ecurity.Permiss ions.UrlIdentit yPermission,
mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken= b77a5c561934e08 9"
version="1"
Url="file://J:/Prog/C#/database.exe"/>
<IPermission class="System.S ecurity.Permiss ions.ZoneIdenti tyPermission,
mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken= b77a5c561934e08 9"
version="1"
Zone="Intranet"/>
</PermissionSet>
Somebody can help me to find the error, and what more i have a login and a
pass to connect to MySQL but i don't know where i put these in the code....

Thanks
Nov 15 '05 #1
3 1390
Well, you would want to put the actual connection to the database in a
try/catch block and output error messages in a MessageBox or something as
the error messages are easier to read and more informative. Note that if
it fails, you should clean up code in a finally block.

You probably need to add User id=myuser;Passw ord=mypass; in the
connectionstrin g.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
For a laugh, try web browsing with Opera's User Mode with Nostalgia enabled
Nov 15 '05 #2
Hi,

Username and password data can be specified in the oleDb
connection string with the "User ID" and "Password"
keywords.

Shamshins Itamar
-----Original Message-----
I want make a connection with MySQL (don't know why, i need, that's all ; ) ) in C#
but i don't know a lots the OleDbConnection , i have do that:
using System;
using System.Data.Ole Db;

class database
{
// OleDbConnection oConn;
// OleDbCommand oCmd;

public void setConnection()
{
OleDbConnection myConnection = new OleDbConnection (
"Provider=M ySQL ODBC 3.51 Driver;Data
Source=192.168 .1.2;Database=g olf;");
string mySelectQuery = "SELECT * FROM golfnews";

myConnection.Op en();
OleDbCommand myCommand = new OleDbCommand (mySelectQuery, myConnection); myCommand.Comma ndTimeout = 20;
OleDbDataReader myReader;
myReader = myCommand.Execu teReader();

while (myReader.Read( ))
{
Console.WriteLi ne(myReader.ToS tring());
}
myReader.Close( );

myConnection.Cl ose();
}
}

class Prog
{
static void Main()
{
database db1 = new database();
db1.setConnecti on();
}
}

but i receive in the output a security error :

exception does not generated : System.Security .SecurityExcept ion: failurefrom the request
at database.setCon nection()
at Prog.Main()

Le jeu autorisé de l'assembly défaillant était :
<PermissionS et class="System.S ecurity.Permiss ionSet"
version="1">
<IPermission class="System.S ecurity.Permiss ions.Environmen tPermission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Read="USERNAME"/>
<IPermission class="System.S ecurity.Permiss ions.FileDialog Permission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Unrestricted="t rue"/>
<IPermission class="System.S ecurity.Permiss ions.FileIOPerm ission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Read="J:\Prog\C #\"
PathDiscovery=" J:\Prog\C#\"/>
<IPermission
class="System. Security.Permis sions.IsolatedS torageFilePerm ission, mscorlib,Version=1.0.50 00.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9" version="1"
Allowed="Assemb lyIsolationByUs er"
UserQuota="9223 372036854775807 "
Expiry="9223372 036854775807"
Permanent="True "/>
<IPermission class="System.S ecurity.Permiss ions.Reflection Permission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Flags="Reflecti onEmit"/>
<IPermission class="System.S ecurity.Permiss ions.SecurityPe rmission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Flags="Assertio n, Execution, BindingRedirect s"/> <IPermission class="System.S ecurity.Permiss ions.UIPermissi on, mscorlib,Version=1.0.50 00.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9" version="1"
Unrestricted="t rue"/>
<IPermission class="System.N et.DnsPermissio n, System, Version=1.0.500 0.0,Culture=neutra l, PublicKeyToken= b77a5c561934e08 9"
version="1"
Unrestricted="t rue"/>
<IPermission class="System.D rawing.Printing .PrintingPermis sion,System.Drawing , Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b03f5f7f11d50a 3a"
version="1"
Level="DefaultP rinting"/>
<IPermission class="System.D iagnostics.Even tLogPermission, System,Version=1.0.50 00.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9" version="1">
<Machine name="."
access="Instrum ent"/>
</IPermission>
<IPermission class="System.S ecurity.Permiss ions.UrlIdentit yPermission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Url="file://J:/Prog/C#/database.exe"/>
<IPermission class="System.S ecurity.Permiss ions.ZoneIdenti tyPermission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Zone="Intranet"/>
</PermissionSet>
Somebody can help me to find the error, and what more i have a login and apass to connect to MySQL but i don't know where i put these in the code....
Thanks
.

Nov 15 '05 #3
Nothing have change!!!!!!!!
"Shamshins Itamar" <an*******@disc ussions.microso ft.com> a écrit dans le
message de news:07******** *************** *****@phx.gbl.. .
Hi,

Username and password data can be specified in the oleDb
connection string with the "User ID" and "Password"
keywords.

Shamshins Itamar
-----Original Message-----
I want make a connection with MySQL (don't know why, i need, that's all ; ) ) in C#
but i don't know a lots the OleDbConnection , i have do that:
using System;
using System.Data.Ole Db;

class database
{
// OleDbConnection oConn;
// OleDbCommand oCmd;

public void setConnection()
{
OleDbConnection myConnection = new OleDbConnection (
"Provider=M ySQL ODBC 3.51 Driver;Data
Source=192.168 .1.2;Database=g olf;");
string mySelectQuery = "SELECT * FROM golfnews";

myConnection.Op en();
OleDbCommand myCommand = new OleDbCommand (mySelectQuery, myConnection); myCommand.Comma ndTimeout = 20;
OleDbDataReader myReader;
myReader = myCommand.Execu teReader();

while (myReader.Read( ))
{
Console.WriteLi ne(myReader.ToS tring());
}
myReader.Close( );

myConnection.Cl ose();
}
}

class Prog
{
static void Main()
{
database db1 = new database();
db1.setConnecti on();
}
}

but i receive in the output a security error :

exception does not generated : System.Security .SecurityExcept ion: failurefrom the request
at database.setCon nection()
at Prog.Main()

Le jeu autorisé de l'assembly défaillant était :
<PermissionS et class="System.S ecurity.Permiss ionSet"
version="1">
<IPermission class="System.S ecurity.Permiss ions.Environmen tPermission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Read="USERNAME"/>
<IPermission class="System.S ecurity.Permiss ions.FileDialog Permission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Unrestricted="t rue"/>
<IPermission class="System.S ecurity.Permiss ions.FileIOPerm ission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Read="J:\Prog\C #\"
PathDiscovery=" J:\Prog\C#\"/>
<IPermission
class="System. Security.Permis sions.IsolatedS torageFilePerm ission, mscorlib,Version=1.0.50 00.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9" version="1"
Allowed="Assemb lyIsolationByUs er"
UserQuota="9223 372036854775807 "
Expiry="9223372 036854775807"
Permanent="True "/>
<IPermission class="System.S ecurity.Permiss ions.Reflection Permission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Flags="Reflecti onEmit"/>
<IPermission class="System.S ecurity.Permiss ions.SecurityPe rmission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Flags="Assertio n, Execution, BindingRedirect s"/> <IPermission class="System.S ecurity.Permiss ions.UIPermissi on, mscorlib,Version=1.0.50 00.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9" version="1"
Unrestricted="t rue"/>
<IPermission class="System.N et.DnsPermissio n, System, Version=1.0.500 0.0,Culture=neutra l, PublicKeyToken= b77a5c561934e08 9"
version="1"
Unrestricted="t rue"/>
<IPermission class="System.D rawing.Printing .PrintingPermis sion,System.Drawing , Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b03f5f7f11d50a 3a"
version="1"
Level="DefaultP rinting"/>
<IPermission class="System.D iagnostics.Even tLogPermission, System,Version=1.0.50 00.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9" version="1">
<Machine name="."
access="Instrum ent"/>
</IPermission>
<IPermission class="System.S ecurity.Permiss ions.UrlIdentit yPermission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Url="file://J:/Prog/C#/database.exe"/>
<IPermission class="System.S ecurity.Permiss ions.ZoneIdenti tyPermission,mscorlib, Version=1.0.500 0.0, Culture=neutral ,
PublicKeyToken =b77a5c561934e0 89"
version="1"
Zone="Intranet"/>
</PermissionSet>
Somebody can help me to find the error, and what more i have a login and apass to connect to MySQL but i don't know where i put these in the code....
Thanks
.

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3937
by: G-Fit | last post by:
Hello group, I have several servers hosting SQL databases. On each of them, I have several databases. All those databases have the same structure (even those on different servers), only the data changes. I made a winforms application that allows me to manage those databases easily, and used several SqlDataAdapter to achieve this, all of them filling the same Dataset which has relations, and this Dataset being the DataSource of a...
11
2436
by: pradeep_TP | last post by:
Hi all, I have a few questions that I have been wanting to ask for long. These are all related to ADO.net and specifically to conenction to database. 1) If I have opened a connection to a database through Connection.open() method, and I do not use Connection.close() method, will garbage collector collect the connection object just because i am not using it any more. 2) I am using a dataset, in which i make some modifications to the...
6
2343
by: Chris Szabo | last post by:
I've created a data access layer for a .NET web application. I'm using C# and framework 1.1. I'm getting an error from time to time when I close a connection saying: System.InvalidOperationException: A connection pooling error has occurred. It doesn't happen each time, the exception is thrown randomly. The big problem is that the connection is left active in the pool. After a short period of time, the pool is filled up and people...
18
3246
by: Rob Nicholson | last post by:
We're getting an occasional occurrence of the following error when two users try and open the same record in our ASP.NET app: "There is already an open DataReader associated with this Connection which must be closed first." As suggested, I was closing the connection in the Finally part of the outer Try but I wasn't closing the data reader as well so I assume that if the following happens, the above error could occur
35
11415
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing Then CType(cn, IDisposable).Dispose() End If I have to admit, I'm not sure what happens here. Will someone explain this line of code (the middle one, not the if statement LOL) to me please?
3
10296
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database I use System.Data.Common.DBConnection and .DBCommand. How can I keep aware from connection losses (network not availeable, db-server not available...)? Are there any strategies to detect this broken connections, and how can I
20
3291
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how many connection has been used ? 2. If the maximum pool size has been reached, what happens when I call the method Open to open the connection ? Will I get an error ? MSDN says the request is queued, but will I get an error in the open method ? ...
3
4891
by: fniles | last post by:
In the Windows application (using VB.NET 2005) I use connection pooling like the following: In the main form load I open a connection using a connection string that I stored in a global variable g_sConnectionString and leave this connection open and not close it until it exits the application. Then on each thread/each subsequent sub that needs the connection I create a local OleDBConnection variable, open the connection using the exact...
0
1982
by: Robert Avery | last post by:
In VBA/VB6, I had a class (incomplete sample below) that watched and displayed for the user all connection events, so that I could easily see what SQL was taking a long time, and when it freezes, I could see what is the SQL that freezes the program. I wanted to replicate this for VB.NET, but the SqlConnection object does not seem to support nearly as rich a set of events as the ADODB.Connection object. Any ideas where these events went,...
0
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.