I'm trying to access Oracle 11g DB.
According to connectionstring.com , the connstring should be :
Driver={Oracle in OraClient11g_home1};Dbq=myTNSServiceName;Uid=user;Pwd=passwd;
Anyhow I'm getting an ArgumentException: 'Driver' is not a valid word.
Thank you.
Greetings
R. Bada
It looks like you are trying to use connection string which is suitable in case of ODBC drivers for Oracle.
You should look for connection string suitable for ODP.NET in Oracle Data Provider for .NET / ODP.NET section. The best is to use one of the following:
Data Source=TNSServiceName;User Id=user;Password=passwd;
or
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=user;Password=passwd;
The first is suitable when you are using TNS, the second allows you to provide the service definition in connection string.
Related
I am having a problem to connect to oracle 11g and I have worked upon it for almost a day now. I am using C# and coding in an Mvc3 way.
I have the following connection string in web.config file
<add name = "VIPSoracleContext"
connectionString = "Data Source=localhost:1521/XE; User Id=SYS; Password=PSWRD;"
providerName="System.Data.OracleClient"/>
I even tried the following connection string again
<add name = "VIPSoracleContext"
connectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=’wkkdmtk’)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME’vipstest’)));User Id=’myID’;Password=’PSWRD’;"
providerName="System.Data.OracleClient"/>
I still have the following error when creating a controller with read/write templates
error:
Unable to retrieve metadata for '...Models.person'.
A null was returned after calling the 'get_ProviderFactory' method on a store provider instance of type 'System.Data.OracleClient.OracleConnection'. The store provider might not be functioning correctly.
How can I successfuly connect to oracle 11g with code first? Can anyone please help.
Thanx in advnce!
I got it atlast guys!
Followed this tutorial:
http://www.youtube.com/watch?v=68tlel4iJdM
But be aware of the default constractor of the context class because if you don't controll it, you will get an error.
Follow this link to check what to take cure of with the default constractor:
Add Controller in MVC4 not working
especially the answer by Arnaldo237.
You will need ODP.net so that provider name Oracle.DataAccess.Client can work.
Enjoy your code at Home.... happy....
How can I connect my Trgovina.mdf with dataGridView?
I follow this tutorial, but it seems that program doesn't find my database.
Connection string looks like that:
string connString = #"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Klemen\documents\visual studio 2012\Projects\Trgovina\Trgovina\Trgovina.mdf;Integrated Security=True";
Everything else is the same as tutorial example.
Error string is An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'
Full code looks like this.
The tutorial you talk about in your question use an Access Database and thus uses the OleDB engine to reach and work with the database. Instead your connection string use the syntax reserved for SQLServer LocalDB.
You should change your objects to SqlConnection (instead of OleDbConnection), SqlCommand (instead of OleDbCommand) and so on...
With these changes you should be able to connect to the automatic instance of SqlServer LocalDB. The rest of the tutorial could work or not, depending on what is present in the MDF file used.
You trying to connect to database .mdf file, but you have a wrong provider.
An MDF is a Microsoft SQL Server database not a Jet Database like
Access (*.mdb). You cannot just connect to the flat file and read it.
You would need to mount the database in an instance of SQL Server.
You could install SQL Server 2005 Express
Source
Note: Just download MS SQL Server 2005 Express or later and you must use the System.Data.SqlClient instead of OLE DB to solve your problem.
So I have the following connection string which is causing me issues. I am attempting to write an application which is capable of being database agnostic (difficult but not impossible) and I have come to testing it on PostgreSQL however I cannot seem to get an OLE connection to work with it. From what I have seen it is entirely possible.
I got everything working using a specific class for PostgreSQL but this used the Npgsql types rather than generic OLE types.
E.g.
private NpgsqlCommand m_postgreSQLDatabaseCommand;
Instead of
private OleDbCommand m_oleDatabaseCommand;
This is not acceptable in my circumstances.
I tried simply changing the connection string to use the Npgsql provider but I am not sure if I am using it correctly. I get the error below:
Connection String:
<add name="ApplicationPostgresDefault"
connectionString="Server=127.0.0.1;Port=5432;
Database=myDatabase;
User Id=myUser;
Password=myPass;
Provider=Npgsql"
/>
Error:
The 'Npgsql' provider is not registered on the local machine.
What can be done to solve this?
If I get the provider in there correctly will I be able to communicate with PostgreSQL as I was with Npgsql objects?
The local machine doesn't have the provider installed.
I would suggest using a native client rather than OleDb anyway:
http://npgsql.projects.postgresql.org/
http://connectionstrings.com/Providers/npgsql
that's your choose
Are you missing a ; after Npgsql ?
I am trying to write C# code to access a database using odbc commands, the database is not local.
My connection string looks like that:
Driver={SQL Server};Server=serverName;Database=dbname;UID=username;PWD=apassword;
Somehow I cannot get the connection to open....
Can someone explain why? am i missing something in the string?
Try this ODBC connection string:
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;
Uid=myUsername;Pwd=myPassword;
as described here
I have an application that needs to connect to a SQL database, and execute a SQL Agent Job.
The connection string I am trying to access is stored in the registry, which is easily enough pulled out.
This appliction is to be run on multiple computers, and I cannot guarantee the format of this connection string being consistent across these computers. Two that I have pulled out for example are:
Data Source=Server1;Initial Catalog=DB1;Integrated Security=SSPI;
Data Source=Server2;Initial Catalog=DB1;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False;
I can use an object of type System.Data.SqlClient.SqlConnection to connect to the database with the first connection string, howevever, I get the following error when I pass the second to it:
keyword not supported: 'provider'
Similarly, I can use the an object of type System.Data.OleDb.OleDbConnection to connect to the database with the second connection string, howevever, I get the following error when I pass the first to it:
An OLEDB Provider was not specified in the ConnectionString'
I can solve this by scanning the string for 'Provider' and doing the connect conditionally, however I can't help but feel that there is a better way of doing this, and handle the connection strings in a more generic fashion.
Does anyone have any suggestions?
The normal way of handling this is storing the ADO.NET provider unique name (separately from the connection string) and using a DB Provider Factory.
Use a SqlConnectionStringBuilder, initialize it with the connection string you find in registry and then read its ConnectionString property, which would normalize the connection string to proper SQL Client syntax.