Issues setting up ASP.net Membership and MySQL database - c#

I'm currently working on a school project which I almost finished. I tested it and it was working fine on my local machine. Then I uploaded it to a webserver to test it and I got an error.
Apparantly you have to configure an external MySQL server and database to get the ASP.net membership system working. (I know it's stupid but I honestly didn't know).
So now I've managed to get a free database (since it's for school purposes it doesn't matter) and I want to save the required information for the membership service in this external database.So now I have to do these three things:
1.Getting to know which columns from the local database I have to insert in the external database (e..g. username: VARCHAR(20) etc.) I need to get this info from my local database...
2 replacing the connectionstring in my web.config file to get it working with my external database.
I searched the web a lot but couldn't find the right thing to do: GETTING TO KNOW THE COLUMNSI read online it was useful to use Microsoft SQL server management. I downloaded it so I could connect to my local (automatically generated) database. I couldn't figure out how to log in. Using my machine name or just a '.' both doesn't work....edit: this is what I mean (picture) what should I do?
REPLACING THE CONNECTIONSTRING
To be honest, I don't understand the connectionstring at all...
If anyone know what to do in these two problems I would really appreciate the help!
Thanks in advance,
Elias

You seemed to ask several questions (above) so I will try to answer enough of them to get you pointed in the right direction.
First, MySQL is not the same as SQL Server. They are different/competing products. From your comments, it sounds like you need to attach a .MDF file which is a "Microsoft Database File". Instead of MySQL, you need to install SQL Express (free). SQL Management Studio will allow you to attach your .MDF file and set up permissions, etc.
Since this is for school, you can use your DB mgr to create a test account with a simple PW. It could be something simple like User: Demo, Pw: D3mooo{ (or whatever you can remember). By default Sql Server only allows you to grant permissions to accounts from your OS. To change that, you can use SSMS, right-click the server, choose Properties, security and change the "Server authentication" to "SQL Server and Windows Authentication mode". Otherwise, you could just grant permission to your IIS server's identity, which is usually some name like [machinename\IUSR] (with square-brackets).
Once that is set, you need to create a "connection string". The easiest way is to create a text file on your desktop and rename it from new text Document.txt to dsn.udl. The file extension is the trick, it must be .udl instead of .txt. If you get it right, the icon will change and you can double-click it and go through the wizard to make/test a connection string. When you are done, you can open the udl file with notepad, and it will contain a working connection string. Copy the connection string into your web.config and things should start working for your membership DB.

Related

ASP.NET deployment to IIS connects to localdb but always shows transient failure error

I am having this problem for more than a day already so I decided to ask for help.
Picture of the Error in IIS deployment
I can successfully test my ASP.NET project on the IIS Express from Visual Studio, the connection string works perfectly. Also, when running my program.exe located in the IIS deployment folder it also connects perfectly to the localdb.
Unfortunately, when using the live IP address of my project the error appears, so my guess is that it is connecting to the DB but it is not being able to retrieve or push data to it for some reason.
I tried to use different methods of DB connection, localdb, shared localdb and SQL Express.
None worked.
My connection string is the following:
Server=(localdb)\\MSSQLLocalDB;Database=PaymentConnect;Trusted_Connection=True;
I have tried to add the EnableRetryOnFailure to my code, unfortunately the error remains, after the allowed tries it fails again.
I literally have no experience deploying projects to IIS, and neither have experience on ASP.NET. If anyone can help me it would be great! Thanks!
If I forgot to add something please let me know so I can update the question
The error unfortunately is generic, it only says that something went wrong and possibly is a transient failure. But my issue is actually solved, for those experiencing the same issue as I am here is how to solve it.
Instead of using localdb you should download and set up SQL Express, it is like a local server but shared with all users on the PC, you will need that because when IIS tries to open your localdb it will actually do so as its own user, and so the localdb is different. Remember to change your connection string on the app, it should look something like this: "DefaultConnection": "Server=.\\SQLEXPRESS;Database=PaymentConnect;Trusted_Connection=True;"
After doing that you need to create a security user on the DB like so:
IIS APPPOOL\nameOfMyAppPool
where nameOfMyAppPool is the name of the Application pool your website is using.
Now after that what I did, which I am not sure is needed, is that I gave this security user sysadmin Server Roles, you will see this when creating this user, also on user mapping you select your DB and give it db_datareader db_datawriter and db_owner for it.
After doing that go to your DB and click to see its properties, you will need to go to permissions and give this new user you just created permissions to:
select delete insert update connect replication execute references control
Once more I would like to remind that this is how I resolved the issue, I am not sure which of these are really necessary or not.
And that should do the trick.

What happens to database connection after software deployment (setup.exe) of C# Winforms?

I was wondering what would happen to a program's connection to the database after compiling it to setup.exe? Will the data from the server explorer be saved somewhere after producing a setup installer so it could dynamically be changed later?
I'm still a bit new in coding. Just barely started.
So I'm not really sure if my questions would make any sense to all the experts.
I hope someone could enlighten me.
Thank you.
It all depends on what form of Database and what settings you had in your project.
case 1:
you are using a server-client Database. Server-client databases are like Sql-Server, MySql, Postgresql, Oracle.....
Usually they have a host, username, password and/or authentication method.
In this case, and while you are configuring your database with in your project in visual studio, you can choose to save the connection string with in your configuration file resources or hard code it in the application.
The Data will stay on the database server.
Case 2:
You are using one of file Database solutions like Sqlite, VistaDB, Acess DB file, XML based DB files, Sql-Compact SQL-CE (obsolete and replaced with SqlExpress)...etc.
In this case, the DB file (which should be in your project file and you have chosen from visual studio the option of (copy if newer)) will be included with your project with the data in it. You have to be sure in this case the proper assemblies are present with you your application *.dll. Your installer have nothing much to do here unless the DB solution you have chosen said other wise.
For example, if you used SqlExpress your installer should be sure that it is present when your user installs your application and if not it either installs it or instruct the user (at least by providing proper links) the methods to install it.
As for the connection string it takes the same conditions of case 1.
Hence you tagged your question with #sql-server I will assume you are looking for the SqlExpress case.
If that's the case I will refer you to the couple of links which will provide you with further details:
1- How do I connect to an MDF database file?
2-How do I connect to an .mdf (Microsoft SQL Server Database File) in a simple web project?
3-C# - Connect to MDF database
4-THE ‘CONNECTION STRING’ STRING OF CONNECTION WITH DATABASE. AN EXAMPLE OF USING IN APPLICATIONS
Finally remember web search is always your friend:
5-c# sql server connection string attach database file (in google search)

How to store SQL Server Database in my App to deploy it?

I'm very new to App deployment. This is my first one actually.
I developed an app which uses a SQL Server database to store its data. I created the SQL Server database with a script. However, neither the script nor the DB itself are part of the "package" of the app. I simply installed SQL Server Management Studio with the default settings, created a new file starting with
USE [Master]
GO
CREATE DATABASE [Database]
and filled up all the details.
The app works in my machine of course, but when I Published the app and got the .Exe, it doesn't work in any other computer, of course because it's not creating a Database to go with it, and the connection string that it uses for the queries is the one that I gave it from my SQL Server instance.
So, I want to know how to actually include the database (or a way to create it) in the "installation package", and also for the program to dynamically get the necessary connection String to operate on any computer where its installed. Right now, I AM fetching the connection string from App.Config with the ConfigurationManager, but of course, the Connection String in App.config is the one that got added when I added MY instance to the project.
Any sort of guidance would be appreciated. I searched related questions but the only ones relevant had some deprecated methods. It's still not very clear to me how it would get the connection string dynamically if its not going to be the same instance.
On a semi-related matter...I noticed that my app was being executed with just double clicking on "setup.exe". Setup seems to imply that it will only install it and add an executable...it's kind of misleading to execute the app itself from the setup, isn't there another way to change that?

How do I upgrade Umbraco CMS from using SQL Server CE to an upgraded version of SQL Server?

I would like to upgrade my Umbraco project on my localhost (and eventually my live website) from running on SQL Server CE to either SQL Server 2014 or SQL Server 2016.
The reason for the upgrade is simple: I may at some point want to manage a website that has more than 4GB of data in the database, is scalable with multiple servers, and I'd like to back things up. Otherwise I'd be lazy and leave Umbraco.sdf alone.
I have not found consistent documentation on this process anywhere. Perhaps one of you might be more experienced with SQL or Umbraco and could help out.
(Aside: For those less familiar with Umbraco, Umbraco is a Content Management System written in C# and JavaScript. There's a SQL file in here named Umbraco.sdf which contents all of the website's contents. )
I figured this out, in case anyone else gets stuck.
Here's how to do it:
Step 1: Port over your current database. With Umbraco, there's an easy way of doing this. Simply install the Export SQL Server Compact package, an addon to your Umbraco CMS. Once installed, follow the directions and generate your SQL file.
Step 2: Import the generated script to SQL Management Studio and run it in a new database. In order to do this: create a new database and give a new user permission settings to access that database (don't use your server login - you can, but it's better to create a user so you can access remotely). After that, go ahead and copy and paste your entire file (yes, that entire file) into a new query (right click the database -> run query), paste the script, and run it.
Step 3: Change the connection string. This is in your web.config. Within the XML tags of , configure something akin to this (remove the {}):
<add name="umbracoDbDSN"
connectionString="Data Source={the ip of your database};Initial Catalog={theDatabaseName};User Id={theUserId};Password={yourPassword}"
providerName="System.Data.SqlClient" />
The nice thing about this connection string is that you can edit locally, as well as on site, with the same connection string. This allows you to test code changes on your localhost, without changing the code on the website. The only thing that is linked automatically is CMS Content.
Make sure not to delete your old Umbraco connection string, in case you want to revert back to it. Simply comment that out.
Step 4: Encrypt the web.config. Clearly it's not wise to keep your database password in plaintext on your website. This MSDN on encrypting your web.config is invaluable.
There are a few things you will lose with this:
Portability of your database. Sometimes you'll want to only have a file be a database instead of a whole server. We only recommend doing this step when your site is essentially done, as configuring a SQL Server and keeping it secure is an extra challenge you shouldn't worry about.
Occasionally, images don't transport. You might have to reinput all of your images manually.
Possible security. Every time you publish your website, you may have to reencrypt the web.config manually. This can be exceedingly dangerous - so make sure your website always has the web.config encrypted, even on new publishes.
SQLCE ToolBox is the best tool for the job. Just install the extension then the steps are as follows:
In Server Explorer add the connection to your new database (Connect To Database button)
Right click on Umbraco.sdf file in in the SQLCE ToolBox and choose Migrate To SQL Server
Choose your server and export.
Modify the umbracoDbDSN connection string to point at new database.
The target database should be empty (or at least not have any conflicting table names).
It seems easiest to do it in webmatrix, have you tried that?
From: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/53818-Convert-Umbraco-SQL-CE-database-to-SQL-Express
or: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/49519-Changing-database-in-Umbraco-7
First you need setup a database in SQL Server. Once that is done, then open the Webmatrix, and in the lower left corner in the webmatrix UI you can select the databas. Then browse to the SQL Server CE database, it's located in the \App_Data folder after that a "migrate button" will appear in the upper menu options. By press that button a migrate dialogue appears asking for connection details to the SQL Server database that you have created.

Move local mssql database to webhosted MYSQL

I'm a dektop developer and don't know much about how webhosting work... So please help me here.
currently my app works with MSSQL database which is installed locally on the same machine.
Now I need to go wider and let multiple apps work with the same database over the Internet.
I have a webhosting with CPanel in it and MySQL database.
Please tell me how I can access tables in that MySQL database from my another computers?
Select and update records in that table. Do I have to implement some functionality using PHP to make such requests?
Please advise..
Exporting raw MS-SQL dumps will probably not work if you try to import into mySQL because there are some differences in syntax. There are commercial programs available that will help you migrate data, otherwise it might be better to code a PHP program to export from MSSQL to mySQL.
But your question sounds more like you're asking how to access databases remotely.
.
PHP can do this natively. When you create your link to the database you specify the host. For example: $databaseConnection = new mysqli('username','password','host_ip_address');
If you're coming from MSSQL you may hit some snares.
To allow remote connections on MS-SQL you use the "surface area" configuration tool. You'll probably find that your mySQL database server is already configured to allow remote connections, if not you'll have to take that up with your host (sounds like you don't have your own box).
The next trick is to remember that usernames in mySQL look like this: 'user'#'host'.
cPanel hosting usually has PHPmyAdmin installed. Open it up and look at the user table in the mysql database (the actual database named mysql running on the MySQL server).
You'll see a host column. So if your 'root' user is only set to 'localhost' you won't be able to login as that user from another machine. The wildcard symbol is %. You can read this up here - http://dev.mysql.com/doc/refman/5.5/en/adding-users.html
Of course the same rules apply to mySQL when it comes to users. Don't use your root account to access sub-databases, rather assign new users which only have the required permissions. Also consider using non-predictable usernames. That doesn't really answer your question (sorry) but it's worth mentioning while you're looking at the user table.
So to finally answer your question:
1) login to cPanel and create your database 'foo'
2) Run SQL command:
GRANT ALL PRIVILEGES ON foo.* TO 'secretuser'#'%' IDENTIFIED BY 'longpassword'
Then PHP code would look something like this:
$host = 'ipaddress or hostname';
$mysqli = new mysqli('secretuser','longpassword',$host,'foo');
// look in php.net for error handling
$query = "SELECT * FROM tablename LIMIT 0,10";
$result = $mysqli->query($query);
The reason I put a limit there is because you're probably used to "SELECT TOP 10"
You would have to export the data on your computer into a raw SQL file, and then using a the PHPMyAdmin control panel you could import it. Assuming you are also using PHPMyAdmin on your own machine there is an 'Export' tab along the top. If you click on that you will have the option to export all your tables to a .sql file.
From there you then need to access PHPMyAdmin via CPanel. Once in you can then hit the 'Import' tab and upload your file to get all the data into the database. To interact with the database online you would need to use the inbuilt functions in PHP - the MySQL Reference on PHP.net is very useful. you would then be able to access the database from any computer using the PHPMyAdmin control panel.

Categories