The Artima Developer Community
Sponsored Link

C# Answers Forum
Assembly Registration - C# Beginner

9 replies on 1 page. Most recent reply: Jul 8, 2009 3:59 PM by kishore chidipudi

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 9 replies on 1 page
Lorna Twiddy

Posts: 3
Nickname: lorna
Registered: Mar, 2004

Assembly Registration - C# Beginner Posted: Mar 24, 2004 5:35 PM
Reply to this message Reply
Advertisement
Hi,

I am totally new to this so please excuse my stupidity! I have stolen some code out of a book to connect to an Oracle database but have amended it to use another provider as my Oracle client software is to advanced to use the OleDb connection that the book used. I have therefore tried to amend the code to use the Microsoft Data Provider for Oracle but keep receiving this error message when I try and compile it:

error CS0234: The type or namespace 'OracleClient' does not exist in the class or namespace 'System.Data' (are you missing an assembly reference?).

I dont know what or how to include one. Can someone show me in real simple terms!

Here is my code (the code that the book suggested has been commented out and then I've added my stuff - sorry about the mess. Thank you):

<code>
/*
LtOleDbConnectionOracle.cs illustrates how to use an
OleDbConnection object to connect to an Oracle database
*/

using System;
using System.Data;
using System.Data.OracleClient;

class LtOleDbConnectionOracle
{

public static void Main()
{
// formulate a string containing the details of the
// database connection
string connectionString =
"data source=TSTASC92;user id=asclepios;password=dom93ut";

// create an OleDbConnection object to connect to the
// database, passing the connection string to the constructor
// OleDbConnection myOleDbConnection =
// new OleDbConnection(connectionString);

OracleConnection oOracleConn = new OracleConnection();
oOracleConn.ConnectionString = "Data Source=netservicename;user id=scott;password=tiger";


// create an OleDbCommand object
OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();

// set the CommandText property of the OleDbCommand object to
// a SQL SELECT statement that retrieves a row from the sec_user_groups table
myOleDbCommand.CommandText =
"SELECT user_code, group_name " +
"FROM sec_user_groups " +
"WHERE user_code = 'SJJ58'";

// open the database connection using the
// Open() method of the SqlConnection object
// myOleDbConnection.Open();
oOracleConn.Open();


// create an OleDbDataReader object and call the ExecuteReader()
// method of the OleDbCommand object to run the SELECT statement
OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();

// read the row from the OleDbDataReader object using
// the Read() method
myOleDbDataReader.Read();

// display the column values
Console.WriteLine("myOleDbDataReader[\"user_code\"] = " +
myOleDbDataReader["empno"]);
Console.WriteLine("myOleDbDataReader[\"group_name\"] = " +
myOleDbDataReader["ename"]);

// close the OleDbDataReader object using the Close() method
myOleDbDataReader.Close();

// close the OleDbConnection object using the Close() method
// myOleDbConnection.Close();
oOracleConn.Close();
}
}


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Assembly Registration - C# Beginner Posted: Mar 25, 2004 10:27 AM
Reply to this message Reply
> I am totally new to this so please excuse my stupidity!

We'll excuse your inexperience, but stupidity can only be pitied. ;-)

Anyway, don't feel stupid. This reference stuff is a bit complicated and it just takes a little immersion to get the hang of it.

To answer your question; if you are using the Visual Studio IDE, then you can right-click on your project in the "Solution Explorer" tool window and choose "Add Reference..." From there, you need to add a reference to System.Data.OracleClient.dll. If you are doing it on the command line, then use the /reference parameter of csc (type "csc /?" for brief syntax help). The full path to that assembly on my system is:
c:\windows\microsoft.net\framework\v1.1.4322\System.Data.OracleClient.dll
(you might be able to refer to it without the full path -- try that out first)

The gist of it is this: Just referring to the namespace in your code is not enough; you also have to tell it what assembly contains this namespace (or at least the parts you want to use). This is different from Java, where they have the naming convention combined with automatic search of the classpath so you don't have to specify the namespace (or, in Java, package) and its repository.

Lorna Twiddy

Posts: 3
Nickname: lorna
Registered: Mar, 2004

Re: Assembly Registration - C# Beginner Posted: Mar 25, 2004 6:15 PM
Reply to this message Reply
Matt,

Thank you so much. I am just so glad that there are people out there like you. You are a good person and have saved me extreme brain ache.

Thanks.

Lorna Twiddy

Posts: 3
Nickname: lorna
Registered: Mar, 2004

Re: Assembly Registration - C# Beginner Posted: Mar 25, 2004 9:03 PM
Reply to this message Reply
Hi Matt

Just one more area of confusion I have.

I have just read in a book about doing what you told me to do. I find it confusing because like you said, with the likes of Java, you don't have to bother doing this.

Anyway, my book says that code behind is totally optional, but obviously it makes real sense to do. But what confuses me is that my books says:

'Remember you dont have to perform this extra step, as ASP.Net will compile your source files for you automatically the first time they are requested by a client'

So how would you make your code use the System dll's etc if you didnt want to create assemblies and just wanted to specify your source file name in an ASP page for that to use.

Is this when I use the 'inherits' command after my page class definition?

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Assembly Registration - C# Beginner Posted: Mar 25, 2004 11:14 PM
Reply to this message Reply
Oh, this is ASP.NET. I was thinking .NET application programming. I haven't done any ASP.NET programming. My web server runs Linux and supports cgi/Perl or PHP, so I've started learning the latter. Beacuse of this I don't have much incentive to learn (or opportunity to practice) ASP.NET, other than for fun.

Nevertheless, just in case someone who really knows what their talking about doesn't post an answer, I'll offer some ideas: If the assembly is in the same directory as the asp page, I think you can simply use imports (not "inherits", as far as I know) and I guess the web server does reflection on every file in that directory to find if the namespace you are after is in one of the assemblies there. It might also automatically look in the GAC, if you've strong named your assembly and installed it there (I'm not sure about this though). Additionally, if you want to have a reference to some assembly that is not in that directory, you need to edit your web.config (I think -- whatever the config file is called, which you probably know better than I) and add a line something like this:
<add assembly="d:\path\to\the\assembly\TheAssembly.dll"/>

I've probably not got these details right (what would be the odds of that?), but maybe this will help point in the direction of the solution.

guest

Posts: 9
Nickname: guest
Registered: Dec, 2003

Re: Assembly Registration - C# Beginner Posted: Jul 21, 2004 11:28 AM
Reply to this message Reply
Thanks for your reply. It was the correct solution for me. Thanks for taking the time to put your knowledge out for others to find!

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Assembly Registration - C# Beginner Posted: Aug 11, 2004 10:02 AM
Reply to this message Reply
Ack. How did I let these literary gaffes through?

> ...Beacuse of this ...

Oops: because

> Nevertheless, just in case someone who really knows what
> their talking about doesn't post an answer ...

Even worse, that should be "...knows what they're..." in modern parlance, or "...knows what he's..." in old style grammer (which is more grammatically correct, but less PC).

Padmini

Posts: 1
Nickname: pnkumar
Registered: Jun, 2005

Assembly Registration - C# Beginner Posted: Jun 27, 2005 12:00 PM
Reply to this message Reply
Please guide me on how to ask questions in this forum .I am a beginner and in need of help. I need some information on Assembly Programming in C#. Reply to this would be appriciated. Thank you.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Assembly Registration - C# Beginner Posted: Jun 28, 2005 9:51 AM
Reply to this message Reply
You should go to the topic list, http://www.artima.com/forums/forum.jsp?forum=76 and post a new topic.

By the way, Assembly Programming and C# Programming are two entirely different things. Probably you want to create a .NET assembly (another different thing from those above, but unfortunately named, resulting in this kind of confusion) and you want to write your code in C#, but you haven't provided the most important information: What do you want this assembly or program to do?

kishore chidipudi

Posts: 1
Nickname: chedipudi
Registered: Jul, 2009

Re: Assembly Registration - C# Beginner Posted: Jul 8, 2009 3:59 PM
Reply to this message Reply
Thank you, Matt Gerrans

Flat View: This topic has 9 replies on 1 page
Topic: insert statement error Previous Topic   Next Topic Topic: yet another dll import question

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use