I am using Visual Studio Community 2015 with SSDT 14.0.6121.0.
I created SQL Server Database Project and added a Schema object. Inside of this, I wrote
CREATE SCHEMA [MySchema]
and created a project snapshot. However, when I deploy this DACPAC (using DacFX), I see, that the actual deploy statement is
CREATE SCHEMA [MySchema] AUTHORIZATION='dbo'
It's always 'dbo', regardless of actual executing account, and it leads to deploy failure due to lack of permissions in some cases.
In DACPAC, code is as follows:
<Element Type="SqlSchema" Name="[MySchema]">
<Relationship Name="Authorizer">
<Entry>
<References ExternalSource="BuiltIns" Name="[dbo]" />
</Entry>
</Relationship>
</Element>
Is there a way to tell SSDT, that I don't want AUTHORIZATION to be 'dbo' or any other account?
No - when SSDT needs to create a schema, it explicitly adds the authorization header and adds the user who owns it - if no one owns it then it puts it as dbo. There is nothing in SSDT to control this and it just does it for you.
Generally it is better to be explicit about these things and add a user who will own it, why can't you specify a user?
Related
I have never used Visual Studio 2017 (or previous versions) before and have been asked to work on a project that includes getting information from a sql database. I am trying to open a connection to the database using an external config and then using configSource in my App config. However when I run this code I get an error: The ConnectionString property has not been initialized. I have been doing a bit of research on this but I'm uncertain of some of VS features and syntax. First, does the ConnectionString need to be initialized in the app config or somewhere else like a module or form? Here are my app config and external config code.
External config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="WindowsApp4.My.MySettings.TrakConnectionString"
connectionString="Data Source=Trak;Initial Catalog=Trak;User
ID=TrakMe;Password = TrakMeData;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
App config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings configSource ="external_conn.config"/>
</configuration>
Thank you for any help.
To answer your question
I have always kept my connection strings in the app.config file. I can't think of a good reason to keep it in a separate file, so I would suggest moving it to app.config.
The Data Source should be the address of the server hosting the SQL database. If this is your machine you should use localhost, if it is a dedicated server you could use the server's IP address.
I don't think it could be the spaces around the equal sign for Password but I would get rid of those if only for consistency. Voodoo might be making your password " TrakMeData"
What I would do
Just let VS handle it by using Entity Framework to make the database connection. Right click in your Solution Explorer and select Add > ADO.NET Entity Data Model, enter a name and select EF Designer from database. Create a "New Connection..." and you'll have a handy dandy interface with a "Test Connection" button so you don't have to keep recompiling to see if the connection string in your app.config is correct. Here's a tutorial (that follows a different path to the same result) with pictures! You can probably skip the database creation bit as I'm assuming you already have one up somewhere.
I have a CLR Project that I'm trying to publish using Visual Studio. I had to change the project to a SQL Data Tools project, and now it's not publishing. Each time I try, I get a timeout error. When I take it step-by-step, I find this line of code hangs on my server.
IF EXISTS (
SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'fwDrawings')
BEGIN
ALTER DATABASE [fwDrawings]
SET READ_COMMITTED_SNAPSHOT OFF;
END
Basically, I know it's trying to force the server into single user mode when I try to publish this up. It's just to my staging server and not to a production server, but this is still a problem. I can't keep kicking everyone off the server and try and switch it to single user mode every time I want to update the CLR while I'm testing it's functionality. And I don't want to wait for a maintenance cycle or down-time to promote it up to production. Is there a way around this?
Presumably you have READ_COMMITTED_SNAPSHOT turned on for your database.
If this is the case, you need to change your Database project settings to match. Check "Read committed snapshot" transaction isolation, within the Operational tab in Database Settings for the project.
For me, this prevented the publish timing out, i.e. I can now publish successfully.
For a safer way to deploy to a server that's in use, try using a schema comparison instead.
I'm a bit confused. I built my MVC 3 project which works fine in my development environment and the integrated IIS in Visual Studio 2010.
After deploying it to an IIS 7 it seemed to work, too. Reading does. But when I try to change some database values, it simply does not do anything. It seems to work, but after a reload of the changed values, they aren't changed at all.
Development database is on a local MS SQL Server 2008 and production on a remote Server with SQL Server 2005 (in this case, but the version will differ later on). Is there any difference? The user in the connection string has full rights, since changing works via Management Studio.
The connection string looks like this:
<add name="MyDBEntities"
connectionString="metadata=
res://*/Models.MyDB.csdl|
res://*/Models.MyDB.ssdl|
res://*/Models.MyDB.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=10.90.0.88;
initial catalog=MyDB;
persist security info=True;
user id=foo;
password=bar;
multipleactiveresultsets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
Thanks in advance.
PS: I build the project with Entity Framework 4.1 which is installed on the server. Well, reading does work though...
I would suggest ensuring that you have the correct connection details. The easiest way I can think of would be :
Create a new text file ( f.e. connection.txt )
Rename '.txt' to '.udl'
Double-click the created connection.udl file
Provide all the required connection details, hit 'Test connection' button
If it works, hit 'OK' button, open the file with Notepad - connection string will be inside of your connection.udl file. If it doesn't work - you need to find out proper server details ( check instance name, port number, if your user has the correct permissions )
First of all, I know that the error I am getting can be resolved by creating reference project (of type Database Server) and then referencing it in my Database project...
However, I find this to be overkill, especially for small teams where there is no specific role separation between developers and db admins..But, let's leave this discussion for another time... Same goes for DACs...Can't use DAC b/c of limited objects supported...
Question
Now, the question is: Can I (and how), disable SQL03006 error when building my Database project. In my case this error is generated because I am creating some users whose logins are "unresolved"...I think this should be possible I hope, since I "know" that logins will exist on the server before I deploy the script...I also don't want to maintain database server project just so I can keep refs resolved (I have nothing besides logins at server level)...
Workaround
Using pre/post deployment scripts, it is trivial to get the secript working...
Workaround Issue
You have to comment out user scripts (which use login references) for workaround...
As soon as you do that, the .sqlpermissions bomb out, saying there is no referenced users...And then you have to comment permissions out and put them in post deploy scripts...
The main disadvantage of this workaround is that you cannot leverage schema compare to its fullest extent (you have to specify to ignore users/logins/permissions)
So again, all I want is
1. to maintain only DB project (no references to DB Server projects)
2. disable/suppress SQL03006 error
3. be able to use schema compare in my DB project
Am I asking for impossible? :)
Cheers
P.S.
If someone is aware of better VS2010 database project templates/tools (for SQL Server 2008 R2) please do share...
There are two workarounds:
1.
Turn off any schema checking (Tools > Options > Database Tools > Schema Compare > SQL Server 200x, then the Object Type tab) for anything user or security related. This is a permanent fix
2.
Go through the schema comparison and mark anything user or security related as Skip and then generate your SQL compare script. This is a per schema comparison fix.
It should be obvious but if you already have scripts in your project that reference logins or roles then delete them and they won't get created.
Background:
I am using the deployment tools in Visual Studio 2010.
I right clicked my project and selected Package/Publish settings. Put all my settings in there ...
I am then using "web deploy" to tranfer the files to my remote server running a remote agent service and this is working fine. The transforms i have on my Web.Release.config do their thing and the server can access the database I created manually.
Problem:
My next step was to get the Database Deployment working too.
I went into the Package / Publish SQL tab and entered my Connection string for the destination database.
(Data Source=MyDBServer;Initial Catalog=Database2;User ID=User;Password=pass)
This database is empty ready to accept the import.
I also enter in the connection string for the source database. This lives on the same server.
(Data Source=MyDBServer;Initial Catalog=Database;User ID=User;Password=pass)
Database Scripting options are set to Schema and Data (changing this makes no difference) and the database scripts are set to [Auto Generated Schema and Data]
When i deploy this now, i get the error:
Error 4 Web deployment task
failed.((09/06/2010 16:41:51) An error
occurred when the request was
processed on the remote computer.)
(09/06/2010 16:41:51) An error
occurred when the request was
processed on the remote computer. The
entry type 'Unknown' was not expected
at this time. The serialization stream
may be corrupted.
Additional Info:
I can successfully create a package with no problems. I looked at the contents in the zip and can see the SQL is generated fine (so no problems connecting to the database). I can then copy this SQL and run it as a new query on the new database and the tables and data are created fine.
I can not seem to work out where this is going wrong, i googled the error and there are no entries on the whole internet. Anyone have any ideas?
Addendum:
To get some further idea of what might be going on, i sent the package across to the server and imported it using IIS. It told me i needed SQL Server Management Objects. So I installed that.
Next attempt it told me my user did not have permission to create the database, I thought excellent this must be the problem. :Granted access - Re-run. Passed!
So i deleted all the tables and went back to VS2010 clicked publish and i get the same error. :(
Sorted it!
Thank goodness, i was totally out of ideas when i went back to a video by hanselman. He mentioned that the Web Deployment Agent can have permissions. I went in had a look and there was a tab in it's properties called log on.
I entered the detials of an account with a decent level of access and clicked okay.
I then restarted the service as requested to enable the changes.
I then went back to VS 2010 and clicked Publish Web.
Music to my eyes, i see the words "Publish succeeded", I check the database and the tables are there. Excellent!
I think i scared the office by getting a little over excited, if you get this problem and this solution fixes it for you, try to hold in the temptation to shout out "YES!, yes, get in!" while laughing maniacally or people will think you're weird like me.