I'm trying to connect to a test database I created for far too long and I finally decided to come for help. I am using F#, Visual Studio Community 2017 and MySQL Database. The server is local (Wamp).
I have this for now:
#r "\...\packages\SQLProvider.1.1.8\lib\FSharp.Data.SqlProvider.dll"
open FSharp.Data.Sql
open FSharp.Data.Sql.Providers
open System.Collections.Generic
open System
[<Literal>]
let connString = "Server=localhost; Database=test1; Uid=root"
let resPath = __SOURCE_DIRECTORY__ + #"..\packages\MySql.Data.8.0.8-dmr\lib\net452"
type sql = SqlDataProvider<
Common.DatabaseProviderTypes.MYSQL,
connString,
ResolutionPath = resPath,
UseOptionTypes = true>
let db = sql.GetDataContext()
And I can't make it work.. 'resPath' gives the error "This is not a valid constant expression or custom attribute value". If I insert a literal '[]' in front of it (see it below), it gives another error: "Strong name validation failed. (Exception from HRESULT: 0x8013141A)".
let [<Literal>] resPath = __SOURCE_DIRECTORY__ + #"..\packages\MySql.Data.8.0.8-dmr\lib\net452"
After connection with the db I want to add information in it and analyze the data of it using F# still.
I don't know what else should I try. All packages are updated, I installed everything through the NuGet package manager and they are all in the references.. I appreciate any ideas / suggestions.
Thank a lot.
SqlDataProvider is a type provider, which means that it contains code that runs at compile time so that it can generate types for you to use at compile time. All parameters to type providers have to be constants that are known at compile time. This is why resPath needs to be a "literal" (effectively the same thing as a compile time constant).
__SOURCE_DIRECTORY__ doesn't have a trailing backslash so you need to add that:
let [<Literal>] resPath = __SOURCE_DIRECTORY__ + #"\..\packages\MySql.Data.8.0.8-dmr\lib\net452"
With this in place I was able to reproduce your Strong name validation failed error. Switching to v6.9.9 (marked as the current version) of MySql.Data fixed that for me.
Related
I am using .NET Core 5 DBContext to access MYSQL Stored procedure to get results with the below code :
var param = new SqlParameter("#word", word);
var result = _context.History.FromSqlRaw("EXEC GETHISTORY #word", param).ToList();
if (result != null)
{
retval = (IEnumerable<HistoryDM>)result;
}
Yet it throws the below exception,
MySql.Data.MySqlClient.MySqlException: 'Only MySqlParameter objects may be stored'
So, what is the error trying to tell me and how can I fix it ?
SqlParameter is for SqlClient, i.e. SQL Server. You want a new MySqlParameter (the connection, command, parameter and reader types are all provider-specific). Or better: ask the connection to create the parameter, or use a tool that will deal with the ADO.NET internals for you.
OK, looks like when one knows it it is relatively simple :
Object result = _context.History.FromSqlInterpolated($"CALL ADDHISTORY ({word})").ToList();
So, both CALL is used (instead of EXEC) and parentheses around the parameter, which is also like the MySQL native call. No black magic here.
Thanks a lot for your support #Marc !!
I allow myself to post my problem, having been looking for the solution for more than two hours, without finding the least solution.
Context: I want to connect to an Access database thanks to the PHP PDO. For that, I have the following code:
public function connect () {
$this->dsn = 'odbc:Driver={Microsoft Access Driver (*.mdb)};charset=UTF-8;Dbq='.$this->dbway.';Uid=;Pwd=;';
$this->user = '';
$this->password = '';
try {
$this->pdo = new PDO($this->dsn, $this->user, $this->password);
die("'eee");
}catch (\PDOException $e) {
die('Error : ' . $e->getMessage());
}
}
$this->dbway = absolute path to the .mdb database
When i try this, i've this response :
Error : : SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][Gestionnaire de pilotes ODBC] Source de donnΘes introuvable et nom de pilote non spΘcifiΘ
Obviously, I tried to find the solution by searching the internet before.
I checked in the administration of ODBC data sources, in the "system data sources", I have:
Name: Microsoft Access Driver
Platform: 32 bits
Driver: Microsoft Access Driver (* .mdb)
So I tried to add the same thing in the user odbc data sources, without success.
I also tried to add the Microsoft Access Driver (* .mdb, * .accdb), which always returns the same error.
Moreover, I checked in php.ini and phpForApache.ini that extension = php_odbc.dll and extension = php_pdo_odbc.dll are really active in PHP extensions, and that's the case
I admit I do not know where to look, and where my concern might come from.
Knowing that the database is present, and that in the ODBC data sources, I see the driver in question, I do not understand why I still can not conquer me.
Thanks to those who will take the time to read me,
have a good day :)
I am using Visual Studio 2013 web form application with MySql database to build a web form application but I have been unable to get past 'Membership and Role Management'.
I used a database first approach for the membership and when I try registering a new user, I get the error message below:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: MySql.Data.MySqlClient.MySqlException: Unknown column 'Extent1.Discriminator' in 'where clause'
Source Error:
Line 16: var manager = new UserManager();
Line 17: var user = new ApplicationUser() { UserName = UserName.Text };
Line 18: IdentityResult result = manager.Create(user, Password.Text);
Line 19: if (result.Succeeded)
Line 20: {
Source File: c:\WebsiteProjects\ASPNETWebProjects\RevenuePortal\RevenuePortal\Account\Register.aspx.cs
Strangely, I do not have an 'Extent1.Discriminator' column anywhere in the database and cannot understand the reason for this frustrating error.
Extent1 is a table alias used by entity framework when it constructs the underlying sql statements. The error means that EF is either not configured correctly or misinterprets your database structure.
You need to analyise the underlying query it generates and determine why EF us3s a field it is not supposed to. Probably a relationship between 2 tables is incorrectly set up.
if possible try to do migration from beginning. from below execution in Nuget package manager:VS 2019 - Tools - NuGet Package Manager - Package Manager Console - run command Add-Migration DBInit - once done, run another command Update-Database.
Above solution is for code first approach.
I had same issue when I changed my system, After did migration it started working for me. Hope same will work for others. happy programming!!
I'm working with EntityFramework 5.0 and MySql. I have generated model from database, and my application now have to connect on multiple database with same structred data.
So i have to dynamic change connection string based on some info.
I try to change database name even from config section of connection string, and with EntityConnectionStringBuilder, but i had the same result: my new connection is stored correctly, but data returned are of the first database.
From WebConfig:
add name="dbIncassiEntities" connectionString="metadata=res:///DAL.Modelincassi.csdl|res:///DAL.Modelincassi.ssdl|res://*/DAL.Modelincassi.msl;provider=Devart.Data.MySql;provider connection string="user id=root ... database=dbname2"" providerName="System.Data.EntityClient" />
From code:
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = providerName;
entityBuilder.ProviderConnectionString = "user id=...database=dbname2";
entityBuilder.Metadata = #"res://*/DAL.Modelincassi.csdl|res://*/DAL.Modelincassi.ssdl|res://*/DAL.Modelincassi.msl";
var context = new dbIncassiEntities(entityBuilder.ToString());
My constructor:
public dbIncassiEntities(string conn)
: base(conn)
{
}
What am i missing?
UPDATE
I can see that calling a query directly from SqlQuery, results returned are correct,
while using the generated entities i retrieve wrong data.
var test = context.Database.SqlQuery<string>(
"SELECT cognomenome FROM addetto limit 0,1").ToList();
But calling..
var oAddetto = from c in context.addettoes select c;
So my problem is only on the model itsself, and manually changing the generated schema
<EntitySet Name="addetto" EntityType="dbIncassiModel.Store.addetto" store:Type="Tables" Schema="dbname2" />
..i'll get the right information.
My question now is: how can i change in code these informations??
Any help is really appreciated!!
Thanks, David
Ok, i've found a workaround for now.
I simply clear the shema name on the designer, and now i can call the generated entities succesfully. Hope this can help anyone else.
David
While I could not remove the Schema in the designer, I removed it directly in the .edmx file. Do a full text search for Schema="YourSchema" in an XML editor of your choice and remove the entries. After that, changing the connection string is enough.
Downside is, the Visual Studio designer and mapping explorer won't work properly anymore.
This seems to be more of a dotConnect issue rather than MySQL, since the problem also exists for the Oracle adapter:
http://forums.devart.com/viewtopic.php?t=17427
I have to do some maintenance on a software that was delivered to a customer.
This software is using database and in order to do some debugging session on my computer, I had to install SQL server 2008 R2 and the two database (MyData and MyRecord) that are used by this software.
I had some troubles doing the setting (login, mapping of the database to sa user) but I managed to go over those issues.
Now I am trying to run the software but it crashes during initialization when it tries to open a recordset.
At first I do the following to connect to the database :
::CoInitialize(NULL);
try
{
HRESULT hr = pConnection.CreateInstance("ADODB.Connection");
if (SUCCEEDED(hr))
{
pConnection->ConnectionTimeout = 0;
CString strConnect;
strConnect.Format(_T("Data Source=MyRecord;uid=sa;pwd=sa123456;"));
hr = pConnection->Open((_bstr_t)strConnect,"","", -1);
}
}
with pConnection defined as :
_ConnectionPtr pConnection;
After that, I am trying to read some data from the database "MyRecord" with the following code :
CString sqlQuery = _T("select * from 通道1设置参数表");
try
{
pRecordset.CreateInstance(_uuidof(Recordset));
pRecordset->Open(_bstr_t(sqlQuery ),pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->Description());
}
with pRecordSet defined as :
_RecordsetPtr pRecordset;
When the line "pRecordset->Open(...)" is run, the software crashes in the function Recordset15::Open(...) of the msado15.tli file.
In this Recordset15::Open function, the raw_Open(...) function returns DB_E_NOTABLE.
However, I am sure that the table dbo.通道1设置参数表 exists in MyRecord database.
The error is :
I don't know if the problem lies in the SQL server configuration or in the code.
This code works perfectly well on the customer's PC so I would go with a configuration problem.
Thanks in advance !!
In the ODBC connector for this database, the setting "Change the default database to" was not set to the MyRecord database.
I have ticked the check-box, selected the database and now it is working correctly.
Your catch statement should be catch(_com_error & e)
MFC often throws exceptions by pointers, however _com_error is a reference.