We have a legacy system running on Universe DBMS 9.6 . We are trying to export data from it and we have enable rpc daemon so that we can connect via odbc.
Now we are able to connect to the server but we are not able to run any queries. We are getting following error
query - SELECT * FROM DEBTOR
exception - UniVerse/SQL: syntax error. Unexpected symbol. Token was
";". Scanned command was SELECT
There are two types of database in universe ie Table and File based. But we are able to query the table based database but we cannot query File based and there are some configurations that will enable querying the File based ones. We are stuck at this place.
Using u2Client library in c# to access the db. Any help is appreciated
Code used to connect Universe
U2ConnectionStringBuilder conn_str = new U2ConnectionStringBuilder();
conn_str.UserID = "id";
conn_str.Password = "pwd";
conn_str.Server = "serverIP";
conn_str.Database = "DBNAME";
conn_str.ServerType = "UNIVERSE";
conn_str.Pooling =false;
conn_str.AccessMode = "Uci";
conn_str.RpcServiceType = "uvserver";
string s = conn_str.ToString();
U2Connection con = new U2Connection();
con.ConnectionString = s;
con.Open();
Console.WriteLine("Connected.........................");
U2Command xmd = new U2Command("SELECT * FROM TABLE_NAME", con);
var op = xmd.ExecuteReader();
Exception catches while executing the last statement
We tried a driver from Rocket software Universe side is working and it is sending the data to the client but client cant understand the protocol or some error that causes exception . We confirmed that the server responded to the query with data by checking the TCP packets. But we are out of luck.
So we decided to create our own software which is developed in Universe Pick Basic which will be connected to external system via ssh and created a new protocol that both client and server understands it. And we succeeded ,now we can export and import data to universe.
Officially Universe 9.6 isn't supported for use with the U2 Toolkit for .NET. Per the documentation (page 6):
Supported versions of UniData and UniVerse
UniData 7.1 or later
UniVerse 10.3 or later
You can still use straight ODBC or UniObjects to extract data from your database. If you're planning to use ODBC, in addition to enabling RPC, make sure you have configured your Universe account for ODBC per Rocket's ODBC documentation. Before writing C# code, I have often verified my ODBC setup using Excel's external data access tools.
Related
I am setting up an azure database to which the CRM 360 Data Export Service (DES) needs to connect. I can do this manually using SSMS and logging on using my azure account.
And then setting up the DES service account as an external provider.
CREATE USER DynamicsDataExportService FROM EXTERNAL PROVIDER
All good, however I wish to automate the process, so I need to logon to the service with in C# and connect and run the code that way.
I am running core 2.2 with System.Data.SqlClient 4.7 using the following code:
var cs = "data source=tcp:dvzxfsdg-sql.database.windows.net,1433;initial catalog=dfsdfs-sqldb; Authentication=Active Directory Integrated";
using (var connection = new SqlConnection(cs))
{
connection.Open();
Annoyingly It gives the error
"System.ArgumentException: 'Keyword not supported: 'authentication'.'".
I am pretty sure the mistake I am making is fairly basic, but I cannot seem to the get to the bottom of it. So any pointers are gratefully received.
You might want to try using the SQLConnectionStringBuilder to properly format your connection string. This helps avoid typos and issues you might be running into with a plaintext connection string. After that, you can actually set the AuthenticationMethod directly on the builder.
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder ()
{
DataSource = "ServerName",
InitialCatalog = "DatabaseName",
etc...
}
builder.Authentication = SqlAuthenticationMethod.ActiveDirectoryInteractive;
SqlConnection sqlConnection = new SqlConnection(builder.ConnectionString);
If the SQL db is an Azure SQL db, then you can view the overview page of the resource and find the "Connection Strings" blade as well. This might help troubleshoot the issue you're having with the connection string you're providing.
Check out this answer about building connection strings for more info
As per title, I would like to request a calculation to a Spark cluster (local/HDInsight in Azure) and get the results back from a C# application.
I acknowledged the existence of Livy which I understand is a REST API application sitting on top of Spark to query it, and I have not found a standard C# API package. Is this the right tool for the job? Is it just missing a well known C# API?
The Spark cluster needs to access Azure Cosmos DB, therefore I need to be able to submit a job including the connector jar library (or its path on the cluster driver) in order for Spark to read data from Cosmos.
As a .NET Spark connector to query data did not seem to exist I wrote one
https://github.com/UnoSD/SparkSharp
It is just a quick implementation, but it does have also a way of querying Cosmos DB using Spark SQL
It's just a C# client for Livy but it should be more than enough.
using (var client = new HdInsightClient("clusterName", "admin", "password"))
using (var session = await client.CreateSessionAsync(config))
{
var sum = await session.ExecuteStatementAsync<int>("val res = 1 + 1\nprintln(res)");
const string sql = "SELECT id, SUM(json.total) AS total FROM cosmos GROUP BY id";
var cosmos = await session.ExecuteCosmosDbSparkSqlQueryAsync<IEnumerable<Result>>
(
"cosmosName",
"cosmosKey",
"cosmosDatabase",
"cosmosCollection",
"cosmosPreferredRegions",
sql
);
}
If your just looking for a way to query your spark cluster using SparkSql then this is a way to do it from C#:
https://github.com/Azure-Samples/hdinsight-dotnet-odbc-spark-sql/blob/master/Program.cs
The console app requires an ODBC driver installed. You can find that here:
https://www.microsoft.com/en-us/download/details.aspx?id=49883
Also the console app has a bug: add this line to the code after the part where the connection string is generated.
Immediately after this line:
connectionString = GetDefaultConnectionString();
Add this line
connectionString = connectionString + "DSN=Sample Microsoft Spark DSN";
If you change the name of the DSN when you install the spark ODBC Driver you will need to change the name in the above line then.
Since you need to access data from Cosmos DB, you could open a Jupyter Notebook on your cluster and ingest data into spark (create a permanent table of your data there) and then use this console app/your c# app to query that data.
If you have a spark job written in scala/python and need to submit it from a C# app then I guess LIVY is the best way to go. I am unsure if Mobius supports that.
Microsoft just released a dataframe based .NET support for Apache Spark via the .NET Foundation OSS. See http://dot.net/spark and http://github.com/dotnet/spark for more details. It is now available in HDInsight per default if you select the correct HDP/Spark version (currently 3.6 and 2.3, soon others as well).
UPDATE:
Long ago I said a clear no to this question.
However times has changed and Microsoft made an effort.
Pleas check out https://dotnet.microsoft.com/apps/data/spark
https://github.com/dotnet/spark
// Create a Spark session
var spark = SparkSession
.Builder()
.AppName("word_count_sample")
.GetOrCreate();
Writing spark applications in C# now is that easy!
OUTDATED:
No, C# is not the tool you should choose if you would like to work with Spark! However if you really want to do the job with it try as mentioned above Mobius
https://github.com/Microsoft/Mobius
Spark has 4 main languages and API-s for them: Scala, Java, Python, R.
If you are looking for a language in production I would not suggest the R API. The Other 3 work well.
For Cosmo DB connection I would suggest: https://github.com/Azure/azure-cosmosdb-spark
i've this code in project "Excel 2007 Addins"
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
string constring = "data source=localhost;user id=fi_archivedb;Password=fi_archivedb";
OracleConnection con = new OracleConnection(constring);
string sql = "select *from TBLFOLDERS";
con.Open();
OracleCommand cmd = new OracleCommand(sql, con);
OracleDataReader dr = cmd.ExecuteReader();
while (dr.Read())
MessageBox.Show(dr[0].ToString());
}
Error=: ORA-12154: TNS:could not resolve the connect identifier specified
Also i've Same code in project windowsApplaction :
private void Form1_Load(object sender, EventArgs e)
{
string constring = "data source=localhost;user id=fi_archivedb;Password=fi_archivedb";
OracleConnection con = new OracleConnection(constring);
string sql= "select *from TBLFOLDERS";
con.Open();
OracleCommand cmd = new OracleCommand(sql, con);
OracleDataReader dr = cmd.ExecuteReader();
while (dr.Read())
MessageBox.Show(dr[0].ToString());
}
In this project "WindowsApplaction" the code correctly without any error.
Where's the problem?
Why does not the code in the project "Excel 2007 Addins"?
The TNS-xxxxx error points out that it is only an Oracle error.
Your connection string is not correctly set up. Oracle has it's own layer on top of I think any network protocol ever invented. It is named "TNS" for "Transparant Network Substrate". Using TNS (also known as "Oracle SQL*Net", also known as "Oracle Net"), you could in the dark ages transparently route packets from SNA to DECNet to IPX to IP based networks and back, without knowing anything about them. Currently, Oracle is switched to IP based only, but most users still use the old TNS layer.
To configure it, see for instance Oracle Net manual
Also, there are some recommendations to allow correct use of Unicode and easy use of a shared location using network files, please see 3.7.5.1.2 of configuration manual of Invantive product
In your case, since it sometimes seems to work, please check that you are comparing two identical installations, so use Excel 32-bit and Windows 32-bit. Or both 64-bit. Oracle has different DLL-s for the number of bits needed. And also different configuration files. As described in 2 you can share configuration files across multiple installation of Oracle SQL*Net using TNS_ADMIN in your registry.
Also note that especially with add-ins using VSTO it can be more complex to get an add-in that installs both into 32 and 64 bit Office environments to load the correct DLL always without hardcoding the versions and shipping the correct Oracle DLL-s with it. Also remember to use ODP, not the Microsoft variant. We've had initially major problems when we started in 2009 getting VSTO add-ins (Invantive Control for 32- and 64-bit Excel, some sheets required 64-bit to handle the full volume of data, please note limitations of .NET array in 4.0, consider 4.5) to run with any Oracle version installed (for instance 32-bit 10g or 11g might be encountered already installed) in combination with any Office version (why o why do people still run 32 bit....). The solution for that I can't share with you. Ultimately we have switched for smaller data volumes (< 4 GB in one request) to our own webservice which disentangles the client side from the server and which ensures that the user doesn't need to install 500 MB of Oracle client software. This might be a viable approach for you too.
Please note that there are others options too using Oracle SQL*Net, such as other directories with the available services as well as putting the following connect string and routing information in the .NET connection string.
Please note that you are missing a space between '' and 'from TBLFOLDERS' and that unnecessarily using a '' when you could suffice with just few fields can introduce performance issues (for instance due to an index not being selected even when it contained all necessary fields) and network bandwidth issues (dragging around a few KB extra on every roundtrip quickly increases the needed bandwidth).
A simple example of a tnsnames configuration file defining the service "XYZ.ACME.COM" or "XYZ":
# Include other file, new releases can nest them.
ifile=tnsnames-invantive.ora
# Direct in tnsnames.ora:
XYZ.ACME.COM=
( description =
( address_list =
( address = (protocol = tcp)(host = 192.1.1.1)(port = 1521)
)
)
( connect_data =
(sid=XYZ)
(global_name = XYZ.ACME.COM)
)
)
Accompanying sqlnet.ora:
NAMES.DIRECTORY_PATH= (TNSNAMES)
NAMES.DEFAULT_DOMAIN=ACME.COM
DEFAULT_SDU_SIZE=65536
RECV_BUF_SIZE=1048576
SEND_BUF_SIZE=1048576
Did this fix your problem?
VS 2008 / C# / MS 2007
I have a Saved Import Feature in Access Database which invokes ODBC Connection. Instead of depending on In-built Saved Import feature, i am trying to rewrite the feature in C# which will call ODBC Connection to Import Data to MS Access Database.
I am not able to call the connection string which is saved in the Access Database which calls ODBC Drivers. I keep failing .. !!
Access.Application access1 = new Access.Application();
try
{
string sSalisburyAccessDB = Server.MapPath("App_Data/Database1.mdb");
access1.OpenCurrentDatabase(sSalisburyAccessDB, true, null);
// Drop the existing table data
access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "plans");
access1.DoCmd.DeleteObject(Access.AcObjectType.acTable, "price");
// Run the saved import
access1.DoCmd.RunSavedImportExport("TestODBC");
// Close the database
access1.CloseCurrentDatabase();
// Quit MS Access
access1.Quit(Access.AcQuitOption.acQuitSaveAll);
Response.Write("successful");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
To me it seems you are using automation in IIS (Server.Mappath... ans Response.Write...) ?
IF this is the case THEN this is NOT supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
Reasons are several: starting from security and not ending with the fact that office was never built for such server usage scenario...
I don't understand why you are not just using ODBC from C# instead of MS Access ? Perhaps you could show some more surce code or the exception/error message... ?
EDIT - after long discussion (see comments):
IF you need to access the Faircom DB then add a using System.Data.Odbc; and try
OdbcConnection DbConnection2Salisbury = new OdbcConnection("DSN=Salisbury;DBQ=S:\;CODEPAGE=1252;");
DbConnection2Salisbury.Open();
After this you are able to use ADO.NET to query etc. the Faircom DB i.e. with OdbcCommand and OdbcDataReader etc.
For some information see http://msdn.microsoft.com/en-us/library/system.data.odbc.aspx
For sample code see http://www.easysoft.com/developer/languages/csharp/ado-net-odbc.html
I'm making an app that will be installed and run on multiple computers, my target is to make an empty local database file that is installed with the app and when user uses the app his database to be filled with the data from the app .
can you provide me with the following examples :
what do I need to do so my app can connect to its local database
how to execute a query with variables from the app for example how would you add to the database the following thing
String abc = "ABC";
String BBB = "Something longer than abc";
and etc
Edit ::
I am using a "local database" created from " add > new item > Local database" so how would i connect to that ? Sorry for the dumb question .. i have never used databases in .net
Depending on the needs you could also consider Sql CE. I'm sure that if you specified the database you're thinking of using, or your requirements if you're usure you would get proper and real examples of connection strings etc.
Edit: Here's code for SqlCe / Sql Compact
public void ConnectListAndSaveSQLCompactExample()
{
// Create a connection to the file datafile.sdf in the program folder
string dbfile = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\datafile.sdf";
SqlCeConnection connection = new SqlCeConnection("datasource=" + dbfile);
// Read all rows from the table test_table into a dataset (note, the adapter automatically opens the connection)
SqlCeDataAdapter adapter = new SqlCeDataAdapter("select * from test_table", connection);
DataSet data = new DataSet();
adapter.Fill(data);
// Add a row to the test_table (assume that table consists of a text column)
data.Tables[0].Rows.Add(new object[] { "New row added by code" });
// Save data back to the databasefile
adapter.Update(data);
// Close
connection.Close();
}
Remember to add a reference to System.Data.SqlServerCe
I'm not seeing anybody suggesting SQL Compact; it's similar to SQLite in that it doesn't require installation and tailors to the low-end database. It grew out of SQL Mobile and as such has a small footprint and limited feature-set, but if you're familiar with Microsoft's SQL offerings it should have some familiarity.
SQL Express is another option, but be aware that it requires a standalone installation and is a bit beefier than you might need for an applciation's local cache. That said it's also quite a bit more powerful than SQL Compact or SQLite.
Seems like you're:
-Making a C# app that will be installed and run on multiple
computers
-That needs a local database (I'm assuming an RDBMS)
-You need to generate a blank database at installation
-You then need to be able to connect to the database and populate it when
the app runs.
In general, it seems that you need to read up on using a small database engine for applications. I'd start by checking out SQLite, especially if you need multi-OS capability (eg., your C# program will run on Microsoft's .NET Framework and Novell's Mono). There are C# wrappers for accessing the SQLite database.
I believe this question is about the "Local Database" item template in Visual Studio:
What are you considering as a database? From what little you've provided in your question, I'd suggest SQLite.
You can get sample code from their site Sqlite.NET
Not sure I fully understand what you're asking but Sqlite is a good option for lightweight, locally deployed database persistence. Have a look here:
http://www.sqlite.org/
and here for an ADO.NET provider..
http://sqlite.phxsoftware.com/
For 1)
The easiest way to provide this functionality is through SQL Server Express User Instances. SQL Server Express is free, so your user does not have to pay additional license for SQL Server, and the User Instance is file-based, which suits your requirement.
For 2)
This is a big topic. You may want to go through some of the tutorials from Microsoft to get the feeling of how to connect to DB, etc.