MVC 5 asp.net want to encrypt the database connection - asp.net

as you know, the database connection parameters are listed in Web.Config which it's text, now the app is hosted in Windows, I want to apply follwoing:
1- exe file by clicking it should ask for the following
a -> database server host address
b -> database server sql user name
c -> database server sql database
d -> database server sql user password
after all the parameters are correct it should allow to store the connection and I will address the connection in webconfig(connection file) is for sure encrypted and it's show only encrypt the server detail(iis server) which even if some one copy the app folder to another server it should not work
--> here I know how to encrypt only in single file but the problem is for developing such exe which should check the detail connection if it's success and by server-IIS detail
where I should start, help of experts saves our time , best wishes
I went trough this answer but could not solve.

Related

Azure login to user db with pyodbc from a Azure webjob

I am trying to login to Azure sql server with pyodbc which logs me in a master db rather than the userdb like 'xyzdb' that i provide in the connection string. The solution to this seems changing to a DSN less based logins that needs configuring the dsn on windows machine.
But i require to run the python script with pyodbc connection from a Azure webjob so configuring dsn is not possible. Hence not able to use the user database as intended. Any solution?
After login to master db i thought to change to user db with "USE xyzdb;" Sql command to which the azure sql server responded 'USE cannot be used to switch between databases' hence xyzdb login cannot be made. I am stuck :).
I made the azure sql server with xyzdb database. Then i tried connection string for newly created server:
pyodbc.connect('Driver={ ODBC Driver 13 for SQL Server};Server=tcp:abc.database.windows.net,1433;Database=xyzdb;
Uid=ur_username;Pwd=ur_password;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;')
This connection string logged me in masterdb not in xyzdb as intended. And As Sql server are physically maintained in stack in data center interconnection is not everytime feasible unless using something as pool elastic. So 'USE xyzdb;' Sql statement from master DB was providing 'USE cannot be used for switching between databases'.
for 3 days i tried with other methods but it didn't worked,so i posted the question.Then i tried the connection string as:
pyodbc.connect('Driver={ODBC Driver 13 for SQL Server};Server=tcp:abc.database.windows.net,1433;
Uid=ur_username;Pwd=ur_password;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;Database=xyzdb')
moving the Database field at the end of the string thinking it will first make a connection with server then it will log me in database xyzdb and It logged me in the xyzdb database.It worked the first time itself.
Now if i try with any of the 2 strings above its working as expected. Don't know what was the issue?.Looks like i wasted time of others as well :). we can remove the question i presume, as i can login the userdb. Thanks.

MSSQL database connection in plesk

I have tried to host my asp.net web site in a free hosting somee.com and it works perfectly with the database.
The problem is, now I want to host it in another server and i make the same steps as done in the first one, but the connection between my website and the database is not working.
The question is: Is there a problem with the configuration of the new server OR the problem is in my code?
ps: I'm using plesk in the new server.
You have to perform some steps for the connection string,
Step 1:
Connect your mssql with you host provided database (by giving all the credentials)
Step 2:
Then By Using Entity Frame work connect your self with that database that you already imported in your local mssql .Entity frame work will embed the connection string automatically in your web.config file.

What is the Data Source syntax SQL Client Connection String to Azure?

I am attempting to configure the connection string in web.confg for an ASP.NET app to connect to Azure DB. I am new to this but am familiar with sql configuration strings to SQL Server. How do I configure the login and data source in the connection string I am building. I haven't ever dealt with the cloud like this. If my db name is DB1 how do I set the Azure path for the data source portion of the connection string. NOTE: I know where to configure it in web.config and know to create a connection object.
Thanks.
In the Azure portal, you can navigate to your database's dashboard and click 'Show connection strings' on the right side. See the first screenshot on the below tutorial:
http://azure.microsoft.com/en-us/documentation/articles/sql-database-dotnet-how-to-use/
To answer your original question, "Data Source" means the same as "Server", it is just your server name, i.e. blah.database.windows.net. All of the connection string keywords (including their synonyms) are documented here: https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28v=vs.110%29.aspx

Moving SQL Server from local computer to server

I kind of new to SQL Server, I always used access db for my sites.
I created a SQL Server on my local computer and now I want to take this db and transfer it to the server. In access all I had to do is, take the mdb file and put it on the server and change the connection string. How can I transfer the SQL Server db to the server?
Is there any file to put on the server ?
Also the connection string isn't a folder but a local computer like this:
Data Source=my-PC;Initial Catalog=storeSQL1;User ID='my-PC\com';Password='';Trusted_Connection=YES;
Who can provide me this connection string for the server (the hosting company) ?
The easiest way would probably be to create a backup of the database on your local machine, then restore that backup on the new server.
Roadmap is:
Do simple backup-restore to move user databases to target server.
Create script on source server, that can recover permissions and login-users pairing
Restore the CLR and TRUSTWORTHY security for databases, that using unsafe assemblies, simpliest way is (in proper DB):
exec sp_changedbowner 'sa' --sa just for example
ALTER DATABASE dbname SET TRUSTWORTHY ON
Enjoy
Depending on your version of SQL Server here is a good article that outlines all the ways to move a SQL Server Database.
http://blogs.msdn.com/b/sreekarm/archive/2009/09/11/move-a-database-from-one-server-to-another-server-in-sql-server-2008.aspx
As for getting the connection string yes the hosting company would provide you with that. Where is the database hosted, you could check their knowledge base articles or if it's an in house data base I'm sure a dba could provide you with that information. It won't change much from what you have but it will change.
I'm not sure what tools your using, but to start you need to do a dump or backup of your current database on your machine. After you do that then you can do and import which should create all the tables and import any data you have.
After the data exists on the server then as far as the connection string, you just need to say the Data Source is the server ip address or host name and change your User ID and Pass to match that server.
If you need more details on any part of this process, post what tools your using and what your environment looks like and I would be more than happy to assist you.
In my opinion the best way to do that is to detach the db from one server(pc), copy the files to the second one and then attach them on the second server/pc.
To detach:
USE master;
GO
EXEC sp_detach_db #dbname = N'AdventureWorks2008R2';
GO
To attach:
USE master;
GO
CREATE DATABASE MyAdventureWorks
ON (FILENAME = 'C:\MySQLServer\AdventureWorks2008R2_Data.mdf'),
(FILENAME = 'C:\MySQLServer\AdventureWorks2008R2_Log.ldf')
FOR ATTACH;
GO

How To Query A Database That's Being Used By Asp.Net

I have a Sql Server 2008 Express database file that's currently being used by an ASP.NET application, and I'm not sure how to query the database without taking the website down.
I'm unable to copy the database files (.mdf and .ldf files) to another directory, since they're in use by the web server. Also, if I attach the databases to an instance of the sql server (using the 'Create Database [DB name] on (filename = '[DB filename.mdf]') for attach;' command at the sqlcmd prompt), then the application pool user becomes unable to access the database (i.e. the webpages start producing http 500 errors. I think this might have to do with the username for the application pool becoming somehow divorced from the login credentials in the sql server database).
Any suggestions? I realize this is probably a newbie question, since it seems like a rather fundamental task. However, due to my inexperience, I really don't know what the answer is, and I'm pretty stumped at this point, since I've tried a couple of different things.
Thanks!
Andrew
if I attach the databases to an instance of the sql server (using the 'Create Database [DB name] on (filename = '[DB filename.mdf]') for attach;' command at the sqlcmd prompt),
Don't do this to a live database - it's attempting to be setup an MDF to be written to by two different databases...
Use Backup/Restore
As you've found, Attach/ReAttach requires the database to be offline - use the Backup/Restore functionality:
MSDN: Using SSMS to Backup the Database
MSDN: Using SSMs to Restore the Backup
Be aware that the backup/restore doesn't maintain logins (& jobs if you have any associated with the database) - you'll have to recreate & sync if using an account other than those with uber access.
Maybe Linked Server would work?
Another alternative would be to setup another SQL Server Express/etc instance on a different box, and use the Linked Server functionality to create a connection to the live/prod data. Use a different account than the one used for the ASP application...

Resources