I am using the following connection string to connect with my access database from vb.net application, but not get connected.
Driver={Microsoft Access Driver (*.mdb)}; Dbq=D:\Projects\tempdb.mdb
It shows me following error
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
My code is below:
Dim odbcConn As OdbcConnection = New OdbcConnection(m_connectionString)
'' Build thr odbc Dataadapter
Dim odbcAdpt As OdbcDataAdapter = New OdbcDataAdapter(QueryToExecute, odbcConn)
odbcAdpt.SelectCommand.CommandType = CommandType.Text
I had connection problems.
My project was not connecting to database because there were no default driver.
I have solved this problem.
If you are using 64-bit OS you must use 64-bit MS office. similarly if you are using 32-bit OS you must need 32-bit MS office.
Be sure that you have all application of same number of bits.
Hopefully it will solve your problem.
Related
I wanted to change MySQL server in my C# app. The app is run in my company and both - old and new MySQL servers are only accessible from the intranet. The problem is I can connect from HeidiSQL software and from python code but not from C#...
I have tried all possible solutions what I found, for ex. disabling firewall, using different packages from NuGet, modifying connection string, I created new console project only to paste various MySQL connection code - always with same error
Message: Unable to connect to any of the specified MySQL hosts.
Source: MySql.Data
Number: 1042
I', using .net Framework 4.5.2 (4.6.1 in my test project) and MySQL Server is '5.6.44-log - MySQL Community Server (GPL)'
One of C# connection code example that I have tested that is NOT working
using MySql.Data.MySqlClient;
public static MySqlConnection DB_connection;
DB_connection = new MySqlConnection(#"Server=MyIP;Database=myDB;Uid=my_user;Pwd=pass;");
try
{
DB_connection.Open();
isConn = true;
}
catch (...)
Working python code run from the same PC
import pymysql
import pprint
connection = pymysql.connect(host='MyIP',
user='my_user',
password='pass',
db='myDB')
try:
with connection.cursor() as cursor:
sql = "select * from table;"
cursor.execute(sql)
# connection.commit()
result = cursor.fetchall()
pprint.pprint(result)
finally:
connection.close()
Don't see anything wrong with your posted connection string but in case your's is a replicated scenario (I mean DB replication exists) then you will have to specify the replicated server IP/hostname as well like
Server=serverAddress1, serverAddress2, serverAddress3;Database=myDataBase;
Uid=myUsername;Pwd=myPassword;
Lately I've been trying to connect a PostgreSQL 9.6 database on my C# project but I've been struggling setting up the connection string correctly due to "Keyword not supported:driver".
After having read tons of information, I downloaded the ODBC.NET, I registered PostgreSQL in ODBC Data Sources (32x), referenced the Microsoft.Data.Odbc.dll in my project's directory and managed to have a successful connection with my database in the Visual Studio's Ultimate 2013, but when it came to accessing the data something went wrong.
This is my connection string and a glimpse of my project:
Furthermore this is my data source information:
If you want to use ODBC to connect to PostgreSQL database use OdbcConnection
You can then instantiate a connection using DSN as ODBC data source identifier.
OdbcConnection DbConnection = new OdbcConnection("DSN=PostgreSQL30");
as specified here
There are also other ways to connect to PostreSQL without using ODBC driver. You might want to look at Npgsql .net library or EntityFramework with Npgsql library. More info about usage can be found here
I am using Microsoft.AnalysisServices.AdomdClient.dll, v13.0.0.0 to to access a Power BI data set from C# code.
Have been experimenting with various connection strings but always get exceptions...
var connectionString = #"Provider=MSOLAP.7;Integrated Security=;Identity Provider=AAD;Data Source=https://analysis.windows.net/powerbi/api;Initial Catalog=XXXX-XXXX-GUID;Location=https://wabi-us-north-central-redirect.analysis.windows.net/xmla?vs=sobe_wowvirtualserver&db=XXX-XXX-GUID;MDX Compatibility= 1; MDX Missing Member Mode= Error; Safety Options= 2; Update Isolation Level= 2;User ID=my#workemail.com;Password=my_pswd;";
var conn = new AdomdConnection(connectionString);
conn.Open(); //throws here
The connection string above produces error
"The connection either timed out or was lost."
This string is based on the .odc file that I downloaded from Power BI, and it works fine from Excel - data is loaded into pivot table, etc. (Excel uses COM driver I guess?)
If I set Integrated Security = SSPI or Basic, the client throws another error saying that neither of them can be used with HTTP.
What is missing in my code? I am looking for a working sample of a connection string for Power BI.
Thanks!
UPDATE:
There is an inner exception for the connection string above:
"The remote name could not be resolved: 'analysis.windows.net'"
This url is what Power BI puts into odc file when I click on ANALYSE IN EXCEL. What url should I use to connect to data from .Net code?
I discovered that to connect to power bi i needed version 19.9.0 , connection will prompt for username and password.
https://www.nuget.org/packages/Microsoft.AnalysisServices.AdomdClient.retail.amd64
https://www.nuget.org/packages/Microsoft.AnalysisServices.retail.amd64
connectionString= $"Provider=MSOLAP;Data Source=powerbi://api.powerbi.com/v1.0/myorg/{workspacename};";
I used the NuGet Package "Microsoft.AnalysisServices.AdomdClient.NetCore.retail.amd64" in my Project with the following Connectionstring:
Provider=MSOLAP;Data Source=powerbi://api.powerbi.com/v1.0/myorg/{WorkspaceName};Initial Catalog=Sales;User ID=app:{ApplicationId}#{TenantID};Password={Application Secret};
More Details here
I hope to make this short and clear enough. I connect to the ODBC without any issues when using Crystal Reports and have previously used the below setup in VS to create apps and it had worked fine. However, now I am receiving the exception below when I call con.Open();
I was wondering how I am able to resolve this issue. Thanks!
{"ERROR [S1000] [Cache ODBC][State : S1000][Native Code
417]\r\n[C:\Program Files (x86)\IIS
Express\iisexpress.exe]\r\nAccess Denied\r\nERROR [01000]
[Microsoft][ODBC Driver Manager] The driver doesn't support the
version of ODBC behavior that the application requested (see
SQLSetEnvAttr)."}
My connection string and methods looks like this:
<connectionStrings>
<remove name="AvatarDBPM"/>
<remove name="AvatarDBCWS"/>
<add name="AvatarDBPM" connectionString="DRIVER={InterSystems ODBC};SERVER=0.0.0.0;PORT=4972;DATABASE=AVPM4972127001;UID=SYSTEMCODE:UN;PWD=MyPsswd;"/>
public DataAccess(string from_date, string to_date)
{
this.from_date = from_date;
this.to_date = to_date;
LOSList = new List<LOS_View_Definition>();
this.PMConnectionString = ConfigurationManager.ConnectionStrings["AvatarDBPM"].ConnectionString;
}
public List<LOS_View_Definition> GetLOSList()
{
#region Command
var command = "my query here";
#endregion
#region get value from DB
try
{
using (OdbcConnection con = new OdbcConnection(PMConnectionString))
{
con.Open();
Try another driver. There are 4 ODBC drivers installed with Cache:
ODBC Version: 2.5, 3.5
Bitness: 32, 64
Also, are you sure, that PORT is not 1972?
Additionally you may supply AUTHENTICATION METHOD=0 parameter.
I think you should use a version of the ODBC driver which is compliant to the requested ODBC specification.If you are using a 64 bit system you should also be using a 64 bit ODBC driver. This error occurs when there is a mismatch between the version of driver installed and the system you are using to compile.
I have written a program in C# to pull some data using OdbcConnection :
using System.Data.Odbc;
......
OdbcConnection OdbcConn =
new OdbcConnection(Properties.Settings.Default.ConnectionString);
OdbcCommand cmd = new OdbcCommand();
//open connection
if (OdbcConn.State != ConnectionState.Open)
{
OdbcConn.Open();
}
In my settings file, I have this ConnectionString:
Dsn=****;uid=userID;pwd=password
However I cannot establish a connection. I have an iseries access driver from IBM corp installed, but if I try MS access then I am able to connect. Any suggestions?
When in doubt (and it involves connections strings): http://www.connectionstrings.com/
On a Windows 64 bit machine, make sure you check if your C# code is compiled in x86 (32-bit), x64, or "Any CPU". Note that if you compile as "Any CPU," it'll choose x64 bit drivers by default.
The 32-bit drivers can be found at C:\windows\SysWOW64\odbcad32.exe. The 32-bit drivers can be found at C:\windows\system32\odbcad32.exe.
First, make sure you verify your connection works with the ODBC Data Source Administrator using the paths I provided earlier. I.e. make a DSN and test it as Turbot suggested. Once you verified this connection works, your connection string can either use the DSN you just created or you can use a DSN free connection string.
For a quick reference, here is a sample of a DSN free connection string using a ODBC driver:
Driver={Progress OpenEdge 11.3 Driver};HOST=wfdscr11.wf.local;Port=1234;DB=MyDatabaseName;UID=John;PWD=Doe
In this example, I had to connect to a Progress database from my C# code and this is the connection string I used without having to specify a DSN. You can see below that the name of the driver is "Progress OpenEdge 11.3 Driver."
I always like to verify the connection using Data source(ODBC) in control panel (assume you are in window environment). Make sure you see the drive available in your ODBC selection and follow the steps to test the connectivity.
as also mentioned above the connections strings website would give you idea what properties and format on which particular driver connectivity