0
votes

I created database in visual studio 2017. After creating database, I added the connection string as in the connection string of properties of database.mdf. And my server name is(LocalDB)\MSSQLLocalDB. I got a warning

Option not supported. Parameter name: attachdbfilename

and an exception

System.InvalidOperationException: 'Fill: SelectCommand.Connection property has not been initialized.'

using System;
using MySql.Data.MySqlClient;

con = new MySqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\rishi\Documents\dbshop.mdf';Integrated Security=True;Connect Timeout=30");
1
Connection strings are their own thing outside of Programming, with one Dedicated website for it: connectionstrings.comChristopher
I could not find any indication MySQL actually supports attaching a Local DB: connectionstrings.com/mysql | Maybe a embedded DB is the droid you were looking for? en.wikipedia.org/wiki/Embedded_databaseChristopher
its better to put connection strings in config file of the projectQwerty
A MDF file is for a SQL Server, not MySqlClient. A Sql Server you need to use using System.Data.SQlClient.jdweng
You are using a SQL Server LocalDB connection string with a MySqlConnection, that is not going to workMark Rotteveel

1 Answers

0
votes

As for the warning, it is because you have written the connection string wrong. So the compiler doesn't understand what you mean when you say "attachdbfilename". It has no idea. So look into this page and get it right: https://www.connectionstrings.com/mysql/

As for the exception, my guess is you haven't set the connection property. You need to put the SQL command within a Using statement that sets the connection.

An example on how to use the using block is here: https://www.dotnetperls.com/sqlconnection