I was currently create a ODBC Connection to the remote server of the web-hosting.
The Access File is at the ftp home directory.
When running in this code , at the m_connection.Open();
var m_result = new DataTable();
try
{
using (OdbcConnection m_connection = new OdbcConnection(connectionDBString))
{
string sql = "SELECT * FROM product";
m_connection.Open();
OdbcDataAdapter dataadapter = new OdbcDataAdapter(sql, m_connection);
dataadapter.Fill(m_result);
m_connection.Dispose();
m_connection.Close();
}
}
catch (Exception e)
{
}
return m_result;
The following exception fails
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not
found and no default driver specified
Is there anyway to claim the dataSource for the ODBC Connection ?
In the cPanel, I only set the DSN and the Path as follows:
DSN : wealthhonesthk-website
Path : e:\virtualhost\domains\wealthhonesthk\home\website.mdb
The below is my part of the web.config
<connectionStrings>
<add
name="ODBCDataConnectionString"
connectionString="DSN=wealthhonesthk-website;Driver={Microsoft Access Driver (*.mdb)};FILEDSN=ftp:/210.245.166.72/home/website.mdb;Dbq=ftp:/210.245.166.72/home/website.mdb;Uid=;Pwd=; curly=false;"
providerName="System.Data.Odbc"
/>
</connectionStrings>
You tend to use a DSN when you don't define a connection string in a config file (like in old VB6 days). Since you're using a config file, you really don't need a DSN. Why not use a connection string like:
Driver={Microsoft Access Driver (*.mdb)};Dbq=ftp://210.245.166.72/home/website.mdb;Uid=Admin;Pwd=;?
Also, having your MDB file mapped to a FTP location may be a problem; why not map a network drive to that location? This way, your connection string might look like:
Driver={Microsoft Access Driver (*.mdb)};Dbq=X:\myNetworkLocation\website.mdb;Uid=Admin;Pwd=;
Lastly, why are you defining a FILEDSN and a Dbq parameter for your connection string?
In short, I'd recommend getting rid of the DSN part of your connection string and use a non-ftp location for your MDB file.
Here is all the information you need on connection strings:
http://www.connectionstrings.com/access
http://www.connectionstrings.com/access-2007
Have a look at following
http://www.connectionstrings.com/
Should help you.
As you are trying to connect to Oracle Database, you might need to have Oracle Client installed.
Related
I have a database called "sistema" using application apex express, I am trying to connect with this code:
private void button1_Click(object sender, EventArgs e)
{
string constr = "Data Source=sistema;User Id=admin;Password=123;";
string ProviderName = "Oracle.ManagedDataAccess.Client";
using (OracleConnection conn = new OracleConnection(constr))
{
try
{
conn.ConnectionString = constr;
conn.Open();
//Get all the schema collections and write to an XML file.
//The XML file name is Oracle.ManagedDataAccess.Client_Schema.xml
DataTable dtSchema = conn.GetSchema();
dtSchema.WriteXml(ProviderName + "_Schema.xml");
MessageBox.Show("YEAH");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show(ex.StackTrace);
}
}
}
This code shows me this error:
ORA-12154: TNS could not resolve the specified connection identified
With this new code:
private void button1_Click(object sender, EventArgs e)
{
string constr = #"Data Source=(DESCRIPTION=
(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost )(PORT=1521)))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=SISTEMA)));
User Id=ADMIN ;Password=123";
string ProviderName = "Oracle.ManagedDataAccess.Client";
using (OracleConnection conn = new OracleConnection(constr))
{
try
{
conn.ConnectionString = constr;
conn.Open();
//Get all the schema collections and write to an XML file.
//The XML file name is Oracle.ManagedDataAccess.Client_Schema.xml
DataTable dtSchema = conn.GetSchema();
dtSchema.WriteXml(ProviderName + "_Schema.xml");
MessageBox.Show("YEAH");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show(ex.StackTrace);
}
}
}
It returns me
User id 'is an invalid connection string attribute
When I try to connect to the database from VS I get this error:
The listener does not currently know the requested service
The database works correctly on Oracle Apex http://localhost:8080/apex and has tables and records created
Also try with uppercase and lowercase names and nothing changes
I do not understand how to connect to my Oracle Apex database in application express, it is confusing, I do not know what to change with respect to normal databases in oracle.
How can I connect to my apex database in c# ?
Problem is your not putting the tns identifier at the right place. If you had added the oracle manage data access package from nuget there will be an added configuration line on your app config/web config.
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="SampleDataSource"
descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=ORCL))) " />
</dataSources>
</version>
</oracle.manageddataaccess.client>
Edi the alias to "sistema" and put your tns connection identifier on the descriptor. like this
<dataSource alias="sistema"
descriptor="(DESCRIPTION=
(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost )(PORT=1521)))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=SISTEMA))) " />
</dataSources>
and use your fist attempt connection string. That will resolve TNS identification error.
OracleConnection cannot resolve the alias. According documentation there are several possibilities to resolve the name in following order:
data source alias in the dataSources section under <oracle.manageddataaccess.client> section in the .NET config file (i.e. machine.config, web.config, user.config).
-> this was already provided by yonas in previous answer
data source alias in the tnsnames.ora file at the location specified by TNS_ADMIN in the .NET config file. Locations can consist of either absolute or relative directory paths.
data source alias in the tnsnames.ora file present in the same directory as the .exe.
Actually the documentation is not fully correct, or let's say "not thorough". Item 2 and 3 applies only if you use local tnsnames.ora file. However, in file sqlnet.ora you may specify different NAMES.DIRECTORY_PATH, e.g. LDAP or EZCONNECT.
So, actually it should be like this
data source alias in the tnsnames.ora file resp. naming method as defined in sqlnet.ora file at the location specified by TNS_ADMIN in the .NET config file. Locations can consist of either absolute or relative directory paths.
data source alias in the tnsnames.ora file resp. naming method as defined in sqlnet.ora file present in the same directory as the .exe.
I am using ASP.net to create a web app. I use OdbcConnection to connect to MySQL. But it seems to create the object but not it doesn't fill up the datasource and dataname fields. I have the famous error
[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Here is my code failing:
OdbcConnection MyConnection;
string MyConString = "DRIVER={MySQL ODBC 5.1 Driver};" + "SERVER=localhost;" + "DATABASE=test;" + "UID=debug_user;" + "PASSWORD=password;" + "OPTION=3";
MyConnection = new OdbcConnection(MyConString);
MyConnection.Open();
I also use to have a connectionstring in my web.config:
<connectionStrings>
<add name="UTRN_DB_ConnectionString" connectionString="DRIVER={MySQL ODBC 5.1 Driver};Database=cjr_db;Server=localhost;UID=cjr_db_user;PWD=password;"/>
</connectionStrings>
I have the driver set in my Data Source Administrator with MySQL. I've uninstall and reinstall everything. I keep getting this error. I Just don't understand why I get this error while I still specify everything (port, etc...) in the connection string and it keep failing
EDIT:
Here is my web.config
<connectionStrings>
<add name="UTRN_DB_ConnectionString" connectionString="Driver={MySQL ODBC 5.1 Driver};Database=cjr_db;Server=localhost;Uid=cjr_db_user;Pwd=password;providerName=(System.Data.Odbc)"/>
</connectionStrings>
and this is how i read it:
string conString = WebConfigurationManager.ConnectionStrings["UTRN_DB_ConnectionString"].ConnectionString;
string conString2 = ConfigurationManager.ConnectionStrings["UTRN_DB_ConnectionString"].ConnectionString;
using (OdbcConnection connection = new System.Data.Odbc.OdbcConnection(conString2))
{
connection.Open();
...
}
The connection string must contain Provider and Data Source as:
string MyConString = "Provider=(Data Provider);Data Source=(Path of source file)"
You have some spelling mistakes in your connection string in the web.config file. It should be Driver instead of DRIVER, Pwd instead of PWD, Uid instead of UID and so on.
Please change your code to the one below
Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
I found the answer of my problem here:
tadaaaam
Basically, you have to seek the difference of your 64bits and 32bits installed on your machine. By default VS is seeking for the 32. And in your ODBC Sources Manager it shows up the 64.
So you either configure your project to seek for the 64 OR install the 32 bits version of MySQL ODBC.
I have a code written in JAVA:
String host = "jdbc:mysql://online/find";
String username = "test";
String password = "test";
And its working fine. But I want to use the same database MySQL with C#. And I am doing this:
try
{
string myConnStr = "Server=//online/find; " +
" Port = 3306; "+
" DATABASE=finder; " +
" UID=test;Password=test;";
MySqlConnection MySqlConn = new MySqlConnection(myConnStr);
MySqlDataAdapter MySqlAdapter = new MySqlDataAdapter();
MySqlAdapter.SelectCommand = new MySqlCommand("Select * from finder.Customer", MySqlConn);
MySqlCommandBuilder cb = new MySqlCommandBuilder(MySqlAdapter);
MySqlConn.Open();
DataSet ds = new DataSet();
MessageBox.Show("Connected");
MySqlConn.Close();
}
But I am getting Error: "Unable to connect to any of the specified mysql hosts"
I even tried with
IP address in connection string but still its not working.
I have checked these posts already:
Unable to connect to any of the specified mysql hosts. C# MySQL
unable to connect to any of the specified mysql hosts. c#
According to the documentation should be:
string myConnStr =
"Database=finder;Data Source=//online/find;Port=3306;User Id=test;Password=test";
However for me Connection strings could be hard to remember.
Its very easy to make a mistake when you write it manually.
One advice is to use the server explorer to connect to your database. Then right click on your database icon > select properties ... you will see the connection string copy and paste .
VoilĂ !
Server Explorer:
Properties:
Did you install the MySQl Connector for Microsoft Application. If yes then add a reference to MySql.dll from your C# application, then use the below connection string
string myConnStr = "server=yourMySqlServerHostorIP; port=MySqlPort;uid=username;pwd=password;initial catalog=dbname";
To download mysql connector go to http://dev.mysql.com/downloads/connector/net/.
Let me know if it works.
My first idea about the issue is "this has nothing to do with param names for username and password". You are not getting an error like:
user "null" cant login
Java and C# work on totally different foundation (Oracle vs. Microsoft) I don't know Java but I think the libraries for connecting to a remote location must be different.
I think the host URL you used is the problem:
Server=//online/find;
I use MySQL with my C# projects and I define the host value as:
localhost or 127.0.0.1
an IP address (xxx.xxx.xxx.xxx)
a host url (my.dbserver.com)
here is a working MySQL connection string:
<add name="dbConnNews"
connectionString="server=xx.xx.xx.xx;database=yyyyy;User
Id=zzzzzz;Password=**********;"
providerName="MySql.Data.MySqlClient" />
Try to connect to the server via IDE Server Explorer --> Data Connections and observe the connection string generated.
Here's my connection string:
sConnection = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\" + lstNet.SelectedItem.ToString() + "\SharedDocs\Documents\Debug\App_File\ggbase.mdb;Jet OLEDB:Database Password=g3n3r4l;";
lstNet is a listbox that contains all computers found in the network.
I'm assuming something else is wrong with my connection string.
According to Connection Strings website, to access a database over LAN, the following connection string format is used:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\serverName\shareName\folder\myDatabase.mdb;User Id=admin;Password=;
I'm assuming that shareName is where my Connection String fails. What is a shareName? And what are the shareNames of Windows XP and Windows Vista / 7 if, say, I placed my database in their Shared Documents / Public Files?
I've tried modifying my connection string into the following:
\C$\Users\Public\Documents\Debug\App_File\ggbase.mdb;Jet OLEDB:Database Password=g3n3r4l;";
And I still get the following error:
"Format of Initialization string does not conform to specification"
May I have some help on this, please?
EDIT: Tried accessing the database in the Public\Documents section of a Windows Vista PC on my network with the following connection string:
\Public\Documents\Debug\App_File\ggbase.mdb;Jet OLEDB:Database Password=g3n3r4l;";
I also tried to access my own (Windows 7 PC) local Public\Documents section using the same connection string, since the serverName can be changed using the program.
Still nothing.
Try this:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\serverName\shareName\folder\myDatabase.mdb; Jet OLEDB:Database Password=g3n3r4l;Persist Security Info=False;"
You must need to test first if you can access the shared path folder on client P.C. And if it can access it there will be no problem.Make sure also that the client user is administrator so it can do CRUD using you app.
Regards
Well, I actually solved it. Wow.
It turns out, there was an extra " at the very end of the connection string from the .ini file.
//Try This One...
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\PIS(ACU).mdb;";
Con = new OleDbConnection(#constr);
Con.Open();
Com = new OleDbCommand();
Com.Connection = Con;
I'm getting this error when trying to open the connection in code as follows:
string queryString = "Insert into Table;
OdbcConnection connection = new OdbcConnection();
connection.ConnectionString = Settings.Default.STIMConnectionString;
OdbcCommand command = new OdbcCommand(queryString,connection);
connection.Open();
command.ExecuteNonQuery();
My Appconfig is as follows:
<add name="WindowsFormsApplicationTransducer.Properties.Settings.STIMConnection"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0; Data Source="D:\Development\SS Observer II Decoder.mdb"" />
What am i doing wrong?
Since you are using the OdbcConnection, I think you need to include the "Driver" information in your connection string.
Data Source is not a valid connection string property. ODBC originally used a data source name, or DSN=dsnname, where the DSN was configured separately on the system. However you can alternatively specify the driver and driver-specific parameters, which in the case of the Microsoft Access driver is at the minimum the file name: Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\Development\SS Observer II Decoder.mdb.
See http://connectionstrings.com/ to see what you need to have.