How to View Data from MySql Database to SQL Server Kentico? - c#

I have MySQL Database that Contain data i want to view in KenticoCMS 7.0
since there is no support from Kentico to MySQL DataBase , i have change the Connection string inside Web.config file
from : SQL Server Connection String
to : MySQL Connection String
and the result was kicking out to configuration Page
<add name="CMSConnectionString" connectionString="Persist Security Info=False;database=SaDb;server=.\SQLExpress;user id=sa;password=P#ssw0rd;Current Language=English;Connection Timeout=240;" />
to reconfigure Database Again like first time i install Kentico
<add name="MySQLConnection" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;Database=test;Uid=root;Pwd=root;" />
is there is any idea about view(just view) mySql data without convert it to SQL Server DB
or making Web service to do this process?

You can't change the main connection string of Kentico database. It results in new database installation as you described. In your situation you will have to develop a custom code to connect to MySql database. Creating a custom webpart may be a good way. Basically what you need to do:
Create a custom webpart - how to do it.
Install MySql drivers - copying assemblies from MySql connector-net into your website bin should be enough. Package can be downloaded here.
Connect to MySql database - tutorial here.
Retrieve and display data in a way you want.

Related

How to change connexion string in a deployed Azure App

I have developed a website application under visual studio using the MVC Pattern and Entity Framework 6.
This web app was linked to a local database.
I've published the application on my azure acc. I also exported the database on Azure following this tutorial.
However, I can't find a way to link the online app to the migrated database.
No data is displayed on the app and when I try to check for the connexion string I get an error , the connexion string hasn't been updated and therefore the app is still trying to target my local database.
I would like to know if anyone might know how to solve this.
EDIT : The problem may be somewhere else, I apparently have two connexions , one for my migrated DB and one for my local db. Perhaps I need to remove the connexion string targetting my local DB but I don't know how to do that
Also, since the Migrated database is a copy from the local one I was using before, do I need to change anything in my Model,views or controller ?
EDIT2 : Thanks to the comment below I was able to override the false Connexion String. However my datas are still not displayed on my application and I haven't found yet what could have happend.
I suspect that my model is still the same model as the one used by the local database as it has the same name. Does anybody know how to change the model to the current model of the online database ?
Thanks.
Because you created your app with entity framework there should be a connection string defined in the web.config file pointing to the local database.
<connectionStrings>
<add name="MyContext" connectionString="..."
providerName="System.Data.SqlClient" />
</connectionStrings>
If you have published your Website as WebApp (App Service) then you can change the connection string for the database under the Application Settings pane on the WebApp Page.
You can override your connection string by creating a connection string settings entry with the name of the connection string in the web.config file.
(For the snippet above - MyContext)

Error attaching existing database entity framework code first

I have created an application using Entity Framework 6 code-first, in ASP.NET MVC 5, and am bin deploying it to my server. Everything works fine, except for the operations/controller actions that involve database usage.
I am uploading the once-generated database file from my computer to the App_Data folder of the server.
Upon deploying, I changed the connection string in my web.config file from:
connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-NERC_Main-20160104065223.mdf;Initial Catalog=aspnet-NERC_Main-20160104065223;Integrated Security=True"
to
connectionString="Data Source=.;AttachDbFilename=|DataDirectory|\aspnet-NERC_Main-20160104065223.mdf;Initial Catalog=aspnet-NERC_Main-20160104065223;Database=aspnet-NERC_Main-20160104065223.mdf;Trusted_Connection=Yes;Integrated Security=True;"
which throws an error of
CREATE DATABASE permission denied in database 'master'.
A probable cause of this is because the present database file is not being attached, and the entity framework is trying to generate a new database in some other, restricted directory.
I read that the AttachDbFileName is valid for SQL Server Express instances only, which in my case doesn't exist.
How can I modify the connection string so that my current, already uploaded database is utilized.
Note:
The remote server has a full installation of SQL Server 2008 R2. The server does not support user instances. My database is not password protected, and hence I've set the Integrated Security property value to True. I'll provide any other information if required.
If you have a full version of SQL Server, you cannot just use AttachDbFileName. Instead, you need to copy the .mdf (and .ldf) to the SQL Server data file location and then you need to attach the database in SQL Server Management Studio to the server instance.
From that point on, you can reference that database in your connection string using the server name, and the logical database name - something like this:
Server=.;Database=aspnet-NERC_Main-20160104065223;Integrated Security=True;
Depending on your database setup, you may or may not be able to use the Integrated Security - maybe you'll need to have a specific SQL Server login and specify that login (and its password) in your connection string instead:
Server=.;Database=aspnet-NERC_Main-20160104065223;User ID=YourUserName;Password=YourPassword
See this site here for a ton of sample of how to build valid connection strings for SQL Server.

how should i use database of one sql machine in an another machine for my winform application?

I Have a C# windows form application which does many functions using the data from the database
Now I have a partner whose is working on the database part on his machine
He has database and i have all the forms and the application logic
How should i import his tables from his database engine ?
We both use SQL server 2008 R2 with database engines installed
I want that when i send my application to his machine (Say B) i should be able to use the database created by B to run the application of machine A(My machine ) ?
We are developing application in Visual studio 2010
Any help would be fantastic .
If it gets on a shared server, you can pull from different sources using different connection strings (using your database or his database, etc.). Here's a sample of connecting to 2 different database using 2 different connection strings in the Config file.
<connectionStrings>
<add name="Conn1" connectionString="Data Source=YourDataSource;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="Conn2" connectionString="Data Source=YourDataSource;uid=YourUserID;pwd=YourPassword;" providerName="System.Data.OracleClient" />
</connectionStrings>
Copying a SQL Server Database will be helpful also, because if a database is on his local machine and neither of you are connected via LAN or some intranet, you can't access it. It needs to be copied or put on a shared server/location where both of you can access it. Otherwise, see the link on how to copy the database.
Copying data from one database to another. This link should also help accomplish the meat of your question.
However, if you solely want "B" to be able to access it, and you don't care about the access, then just deploy your executable and change the connection string in his config file.
Also, see Vladimir's post regarding 'Backup'.
Easiest thing to do would be to run full backup on database in question. Below is sample of backup script.
USE YourDatabaseName;
GO
BACKUP DATABASE YourDatabaseName
TO DISK = 'C:\Backup\YourDatabaseName.Bak'
WITH FORMAT,
MEDIANAME = 'C_FullBackup',
NAME = 'Full Backup of YourDatabaseName';
GO
Documentaion on BACKUP http://technet.microsoft.com/en-us/library/ms187510.aspx#TsqlProcedure
Once backup is done copy the file over to your machine. Now you need to restore database from backup.
RESTORE DATABASE YourDatabaseName
FROM DISK = N'(path to your BAK file)'
WITH FILE = 1,
MOVE N'(your DB name)' TO N'(your SQL path)database.MDF',
MOVE N'(your DB name)_LOG' TO N'(your SQL path)database_LOG.LDF',
NOUNLOAD,
REPLACE,
STATS = 10
GO
Documenation on RESTORE http://technet.microsoft.com/en-us/library/ms186858.aspx

connect database with dataGridView

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.

Can't connect to shared hosting database with site

Slightly at my wits end. Built an application, running fine locally. Migrated my database to MSSQL without issue, uploaded the site, can't seem to get the application to connect to the database. Any page that accesses the database I get a generic error message.
I've tried all the separate combinations of connection strings I could think of using the Godaddy recommended connection strings. Perhaps I am overlooking something simple?
I'm using Entity Framework Code-First -- My context model is called CombosContext.
<add name="CombosContext" connectionString=" Server=jelatin.db.9508732.hostedresource.com; Database=jelatin; User ID=jelatin; Password=********; Trusted_Connection=False" providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString=" Server=jelatin.db.9508732.hostedresource.com; Database=jelatin; User ID=jelatin; Password=********; Trusted_Connection=False" providerName="System.Data.SqlClient" />
Server: jelatin.db.9508732.hostedresource.com
DB name: jelatin
user: jelatin
Table: Comboes
I'm unfamiliar with GoDaddy hosted SQL, but usually a connection string to MS SQL Server uses "Data Source" instead of "Server" and "Initial Catalog" instead of "Database".
UPDATE
I didn't realize Server and Database were allowed options in the Connection String. Sorry for the confusion.
Regarding the database itself - are you letting EF create the database? Does the user have permission on GoDaddy's system to create a database?
If you have already created the database, did you populate anything? I have found that EF Code First won't correctly populate the database if the database exists and the metadata table doesn't. If you can, try copying your local database up to GoDaddy, and see if the connection works.
Finally, for your generic error message - is it coming back in a 500 error? If so, have you tried using either IE or Chrome's dev tools to inspect the response? Better error information is usually hidden in there.

Categories

Resources