allow to auto generate DBs in sql server under windows authentication - sql-server

In my web.config I have defined following connection string for a Database that not existing in sqlexpress (code first entity framework approach)
<connectionStrings>
<add name="cityconnectionstring" connectionString="Data Source=.\sqlexpress;Initial Catalog=CityPolulation;Integrated Security=True;MultipleActiveResultSets=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
So once I define this on web.config file I can see cityconnectionstring listed under Server Explorer window Data Conncetion in Visual Studio.
But When I trying to Right Click on above connection string and hit Refresh I'm getting following error in Visual Studio.
Server Explorer Error
server explorer unable to perform this operation see below for
details.
Cannot open database "CityPolulation" requested by the login. The
login failed. Login failed for user 'PC-name\username'.
All the answers related to above error are for existing DBs.
How to set permission that can connect to sqlserver for not existing DBs under Windows Authentication.
What are the Settings I should look in IIS or SQL server Management Studio

When the connection is verified it checks that you have access to the database. If the database does not exist then you cannot verify the connection.
If as your question's title suggests, you want to create the database, then you will still need to connect to a database first. IF you have permissions to create a database then you will certainly have access to the "master" database.
However, I hope that you are not expecting all users to be able to create a database as that would mean that all of your users have far too many permissions to the server!
EDIT Change the connection's database to "master". That will prove that you can connect.
Then manually (in SSMS or whichever tool you use) Create the new database on the server.
Now modify your connection to use the new database connection. You should now be able to connect.
Entity Framework is not capable of creating databases. However, once you have created the database it can create tables and data.

Related

Umbraco Database Connection Credentials

Where can I find the database credentials of my umbraco database?
In web.config there is just the following line:
<add name="umbracoDbDSN" connectionString="Data Source=|DataDirectory|\Umbraco.sdf;Flush Interval=1;" providerName="System.Data.SqlServerCe.4.0" />
Which provides insufficient information...
Your connection string clearly shows that you're using default SQL Server CE database (Umbraco.sdf). You can find the Umbraco.sdf file in the /App_Data folder.
Depends on your requirement you can convert the SQL Server CE database to SQL Server Express or open up your solution in Webmatrix to see database tables.
You can find more information on conversion here https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/53818-Convert-Umbraco-SQL-CE-database-to-SQL-Express
To view database tables from webmatrix, you need to open up your solution and click the tab called databases.
umbracoUser is the table where you can find users.
It seems that you are using SQL Server CE and not a SQL Server instance

Getting Error: 'Cannot execute as the database principal because the principal does not exist...'

I am getting the error 'Cannot execute as the database principal because the principal "kc" does not exist...' when I try to execute a Microsoft web application locally that connects to a SQL Server database. It application works fine when it is connecting to a remote server.
I copied the database on the remote server to my local computer to make changes.
This is the connection string when connecting to the remote server:
<add name="Database" connectionString="Server=KC-DEV2;Database=ICKC;User Id=kc;Password=kc" providerName="System.Data.SqlClient" />
The owner of the database is 'KC\Administrator'. I use SQL Server Authentication.
The connection string when I am connected to the database locally is as follows:
<add name="Database" connectionString="Server=localhost;Database=ICKC;Trusted_Connection=Yes;" providerName="System.Data.SqlClient" />
I restored the remote database to my local computer. The owner of the ICKC database is KC\GSantin.
I connect to the database using Windows Authentication.
From what I found on the web, this error can often be from no owner on the database but that is not the case for me. There is a login for 'kc' in the local database. It is a backup and restore of the remoste one so everything is the same.
Does anybody have any suggestions how I can fix this problem?
Thanks,
Gloria
kc should be a SQL Login based on your remote server. Once you restore the database from remote server to local, the SQL user came along. You must have created kc SQL login manually.
What is going to miss here would be mapping between them.
can you run sp_change_users_logins 'Report' and check if there is any orphan users. mostly you should see kc.
If yes then
run sp_change_users_logins 'update_one','kc','kc'
Else You need to capture profiler trace to find exact point of failure.

Error while trying to connect to SQL Server - localhost

I have checked the instance name, auto close is set to true, allow remote connections on the server is checked. The server is running when I open the SQL Server configuration manager. I have even rebooted. I have created this db the same way as all others. I use Entity Framework and have checked the names in the web.config and they match. This is the default connection string from the wizard - I use for testing before I deploy. I just can't think of anything else to check to figure out why it won't connect. Working inside SQL Server everything is fine.
Here is the general error.
A network-related or instance-specific error occurred while establishing a connection to SQL >Server. The server was not found or was not accessible. Verify that the instance name is >correct and that SQL Server is configured to allow remote connections. (provider: Shared >Memory Provider, error: 40 - Could not open a connection to SQL Server)
Config:
connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQL_1;attachdbfilename="C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.SQL_1\MSSQL\DATA\A_db.mdf";integrated security=True;connect timeout=10;user instance=True;multipleactiveresultsets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
Thanks in advance.
Let me preface this answer by saying that proper setup of a SQL instance is not as easy as Microsoft would like you to think with the entity framework. It's a little bit involved and requires that you put your DBA hat on for a little bit.
The error you have indicates that the web instance is attempting to connect to the SQL server using Windows Integrated Security. This will work fine if (a) the windows user that the process is running as (which can be configured in IIS) is authorized to log on to the SQL server and has a valid login in the database and (b) if the SQL server is on the same machine or in the same domain as the IIS server.
In light of this, I recommend using SQL Server authentication. If you need to know how to do this, I recommend searching for "SQL Server Authentication setup" - here is an article that I found which might help you set this up.
http://msdn.microsoft.com/en-us/library/aa337562.aspx
In general, I recommend taking the following actions:
Connect to the sql server using MS SQL Management Studio.
Permanently attach your database, then use the Initial Catalog property on your connection string rather than AttachDbFileName
Then set up your login username and password on the SQL server, and create a login in the database for it.
Make sure your login can only execute the stored procedures you want it to execute. Deny it access to running sql statements.
You will also need to add the username and password to your connection string, and set IntegratedSecurity=false.
Let us know how things go once you get your SQL server set up properly.
This error means that your provider code cannot find the SQL Server. If you have checked the server instance name (it should be <yourLocalServer>\SQL_1), then it could be the attachdbfilename= parameter, as this is a really unreliable way to specify the database to connect to (you should be using the Database Name, not the file name), because there are about a hundred reasons that the file name could change that have nothing to do with your application.

Client side application help requested

I am testing an application. In tableadapter configuration wizard, On server side:
While choosing data source, I chose Microsoft SQL Server Database File.
This gave the connection string as:
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True
Is this correct?
Any way this works in my desired way.
Then in SQL Server Mgmt Express, I attached the database to the instance of my SQL Server Express (to MyhomeServer\SQLExpress"
Now I want to use the same application on Client side (off course databse is stored in Data Directory of my application in Server Side) Now in tableadapter wizard, I choose Microsoft SQL Server Express. Is that correct?
I have done all configurations for remote connection etc. and also done the firewall settings. When I run this test on client side, it returns error:
Cannot open database "Database1.mdf" requested by the login. The login failed. Login failed for user 'MYHOMESERVER\Kh. Furqn'.
Why does it go to Kh. Furqan while I am giving it SQLExpress, where the DB is attached. My server is MyHomeServer\SQLExpress and connection is MyHomeServer\Kh. Furqan (Authentication is Windows Authentication, and no password for it)
Since you chose integrated security the program will try to log onto SQL Server with the current logged on user's credentials - 'MYHOMESERVER\Kh. Furqn'. So the first place I would check is make sure that you can log onto Sql Server Mgmt Studio (SSMS) Express with the windows logon option and logged into the server as Kh. Furqn. Let me know if that works.
Wade

SQL Server - Database 'Database' does not exist. Make sure that the name is entered correctly

I'm trying to generate my database tables from my Entity Framework model, but I'm getting this error when I execute the generation query:
Database 'Database' does not exist. Make sure that the name is entered correctly.
I'm able to connect to the local server just fine.
My connection string, which was generated by VS when I selected 'Database.mdf':
metadata=res://*/Models.Models.csdl|res://*/Models.Models.ssdl|res://*/Models.Models.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
The database definitely exists, but I've noticed that the only databases it's picking up on the server are called master, model, msdb and tempdb.
Can anyone help?
Edit: I've just realised that the SQL connection dialog that comes up when you click "Execute SQL" allows you to connect to a server. But my DB isn't on a server, it's just a user instance database. But that's the only option, so how would I execute against my database? I have the database open in the 'Server Explorer'.
The connection string is referring to a user instance database is that what you intended? I got the impression possibly not from the question.
If not try changing it to Data Source=ServerName\InstanceName;Initial Catalog=Database;Integrated Security=True;
If you are using a user instance database, specify the full path to the location of the database with USE directive.
For example:
USE [C:\Project\Database.mdf]
GO
When connecting the server, you need to select another data source, then enter the name of the local server on which the database is located.
I can't speak for Entity Framework, but within SQL, "database" is a (very) reserved word. Try calling your database (and it's files) something else, even if just "MyDatabase".
I faced such problem when running a script in SQL Server Management Studio to do some stuff on my Local SQL Server. I noticed that the Query Window that I was running the script in was connected to a Remote SQL Server not my local machine.

Resources