Connection string in appsettings.json for remote database - sql-server

I have hosting account in plesk panel. I can create and remove a database in hosting panel.
Now I want to create a database from my local computer using add-migration in code first approach. but the following error occurs:
"login failed for the user [myUserId]"
The connection string in appsettings.json is:
"CourseConnection": "Data Source = host-ip,1433; Initial Catalog=mydb;User ID=myuserid;Password=mypassword"
There are two options to create databases on hosting panel:
localhost:3306(default for mysql)
localhost(default for MS sql v13.0...)
I think that provider name is not mentioned in connectionstring but appsettings.json works fine on my local machine without provider name: System.Data.SqlClient.

after hours of try and error , the problem solved as follows:
i created the database in plesk panel and created a new user .
then assign that user to the database . then in package-manager-console applied update-database command to apply migration that was already added.
i used the same connection string in appsettings.json ,it worked successfully.all table created and migration applied .
it may be helpful for someone.
regards

Related

Connecting to sql database

(I am a sql noob and I just can not figure this out on my own)
For some time now I have been trying to establish a connection to a SQL database in codename one but to no avail. First I tried connecting to a MariaDB database from one.com. All that's needed for the connection is
Database db = Display.getInstance().openOrCreate("databaseName");
if I am not mistaken, but I am guessing this implies that I have somehow already established a connection to the database. This is not the case however so it creates a new .sql file, right? I can recall that you can connect to a database in the services tab in Netbeans. I chose the MySQL(Connector/ J Driver) which should work with MariaDB, or should it? I entered all my data and i says that it can not establish connection to the database.
the error i get
So I thought I might as well try using localhost. I used XAMPP to host a database and connected in the netbeans services tab.
connected?
Now testing was needed to see if this works. I started the SQL journey with this https://www.codenameone.com/manual/files-storage-networking.html#_sql and integrated the part after "You can probably integrate this code into your app as a debugging tool". I changed database name to "mybase" (it's existance can be confirmed in picture 2). Ran the app, opened the dialog, entered "select ID from customers" and got: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: customers) It does not get past the first call to "executeQuery". The customers table definitely exists so what am I missing to establish connection?
I really need instructions to connect to the localhost database and ideally also to the one hosted by my webhost provider.
Thanks,
Jona
The Database class is to access the SQLite DB on the mobile device. To connect to external databases, you'd have to do something different, such as a ConnectionRequest or Socket I think.

Asp.NET MVC 4 deployment issues related to LocalDb and SQLExpress

I am trying to deploy a Asp.NET MVC 4 app to a third-party host, and encountered some problems while following this tutorial.
The tutorial created 2 New SQL Server Database, and set the Remote connection string of DefaultConnection to one SQLExpress database and that of SchoolContext to another. However, I want to have only one database, so I only created one New SQL Server Database, and used the same connection string for DefaultConnection AND MyAppContext. Would this cause problem?
Right now my app won't publish with the following error. not sure if it stems from this. MyAppUsr comes from a Grant script, Grant.sql, that I developed from this tutorial.
Error 3 Web deployment task failed. (An error occurred during execution of the database script. The error occurred between the following lines of the script: "8" and "11". The verbose log might have more information about the error. The command started with the following:
"CREATE USER [MyAppUsr] "
The login already has an account under a different user name. http://go.microsoft.com/fwlink/?LinkId=178587 Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_SQL_EXECUTION_FAILURE.) 0 0 MvcCP
MyAppContext uses LocalDb instead of SQLExpress. The deployment in the tutorial uses SQLExpress. Can I just create a new SQLExpress database and have MyAppContext (LocalDb) "points to" the SQLExpress database?
You must have run the script at least once prior, correct? Because what it is saying is that the user [MyAppUsr] already exists. You will need to drop the user first, then rerun it. ie:
DROP USER [MyAppUsr]
You can embed that into your script, better yet, put a conditional check if exists...

Parallels Plesk Panel connecting to database server connection string

I am using Entity Framework to access the data from my database. It's an MVC application and works fine locally. When I deploy the application on hosting (Parallels Plesk Panel, MS hosting) I get problems with accessing the SQL server instance. There are options in the cPanel which hold connection strings.
LocalSqlServer:
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
xContainer:metadata=res:///Models.x.csdl|res:///Models.x.ssdl|res://*/Models.x.msl;provider=System.Data.SqlClient;provider connection string=
When I upload the site xContainer is generated alone. I found the sql server's instance name and applied it to the data source. In my web.config file I am using the the xContainer. The code after this paragraph is what it seems logic to me to add after the connection string= in the xContainer.
I have tried this with various properties. Data source, initial catalog, and the other info are filled into the conn string (here I am showing only /).
Data Source=x;Initial Catalog=/;Persist Security Info=True;User ID=/;Password=/;MultipleActiveResultSets=True providerName=
The error I receive is that the sql server instance cannot be found. If I add the last piece of code to the container it tells that I don't have a providerName, After adding a providerName the string is deleted to the starting xContainer string:
metadata=res:///Models.x.csdl|res:///Models.x.ssdl|res://*/Models.x.msl;provider=System.Data.SqlClient;provider connection string=
The error I receive is that the **sql server instance cannot be found**.
So, what is the SQL instance name? :)
it maybe not ".\SQLEXPRESS" but ".\SQLEXPRESS2012" or even ".\MSSQLSERVER" or anything else.
You will need to Edit the Web.Config file manually. The ASP.NET Settings page will remove the providerName.
An example of a connection string using EntityClient is below. You can remove the metadata information if you're not using an Entity Model. You will notice the providerName is outside of the actual connectionString and is the reason you will need to edit the file manually.
connectionString="metadata=ModelInformation;provider=System.Data.SqlClient;provider connection string="data source=IP;initial catalog=DATABASE;User ID=USERNAME;Password=PASSWORD;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient"

Use local database from master in MS SQLEXPRESS

I have created a local db using SQLEXPRESS through Visual Basic.
I intend to use LINQ to connect to the database from the application. Here is my statement to initially connect to the database:
Dim db As New DataContext("Data Source=localhost\SQLEXPRESS; Initial Catalog=master; Integrated Security=True;")
Ideally, my database would be entered for Initial Catalog, but that was giving me authentication errors for some reason. Now that this statement executes, my next step is to connect to my specific database. However, when I try to connect with a statement like this:
Dim TestCommand = db.ExecuteCommand("Use MyDB.mdf")
I get an error that the database does not exist.
When I query my database with the following commands:
SELECT name FROM master.sys.databases
The returned values are master, tempdb, model, msdb, and C:USERS\MY NAME\DOCUMENTS\MyDB.mdf
I have tried the above "TestCommand" writing out the directory for the database, but I get an error at "C:".
So, my db exists, but can someone explain to me the syntax I should use to "USE" my database?
You should not use the use command this way! You must connect to the application's database directly by setting it as Initial Catalog. If you're not authorized to do so, a use command won't let you either, by the way. So you have to fix the authorization for the database: create a login for your windows account in Sql Server Management Studio and grant it read/write access to the application's database.

Connect to a heroku database with pgadmin

I would like to manage my Heroku database with pgadmin client. By now, I've been doing this with psql.
When I use data from heroku pg:credentials to connect de DB using pgadmin, I obtain:
An error has occurred:
Error connecting to the server: FATAL: permission denied for database
"postgres" DETAIL: User does not have CONNECT privilege.
How to achieve the connection?
Open the "Properties" of the Heroku server in pgAdminIII and change the "Maintenance DB" value to be the name of the database you want to connect to.
The default setup is suitable for DBAs et al who can connect to any database on the server, but apparently that isn't true in your case.
After you change the Maintenance DB name as suggested by araqnid's answer above, you should also add your database to the DB restrictions field because without this you will see thousands of databases and you may not be able to find yours in the list if the list is too long.
More details here - How to hide databases that I am not allowed to access
This is for pgAdmin 4
In order to connect pgAdmin to your database (postgres instance in Heroku), do the following:
Login to Heroku, and select the application in which you have the database
Select the Resources tab and then click on "Heroku Postgres Ad-on" (see below). This will open up a new tab.
Select the Settings tab and then click on "View Credentials..." (see below)
You will get the following information that you will use in pgAdmin:
Go to pgAdmin, and create a new server
In the General tab, give a useful name
In the Connection tab, fill the info you got at Heroku
In order to avoid seeing thousands of databases, you need to add your database name to DB restriction in the Advanced tab (see below)
We require SSL for connections outside Heroku. Please verify whether you're forcing SSL in your client.
Answered more thoroughly here: Connecting pgAdmin3 to Postgres on Heroku
We don't allow connections to the postgres database, so be sure to set Maintenance DB to your database name, and be sure to use SSL.
Change the Maintenance Database to the name of your Database, e.g. dva70000p0090. This should work.
the db password local isnt the same db password heroku. please check the heroku ip postgtres address and extrac

Resources