How to connect to SQL database from Visual Studio/ open .mdf file - visual-studio-2012

If I copy an .mdf file created by SQL server management studio and put it in the app_data folder I get this error:
"This database file is not compatible with the current instance of SQL Server.
To resolve this issue, you must upgrade the database file by creating a new data connection, or you must modify the existing connection to this database file.
For more information, see http://go.microsoft.com/fwlink/?LinkId=235986"
And if I attempt to Add connection using the visual studio wizard, choosing the Microsoft SQL server database file and select the file I get this error:
"
Unable to open physical file "path" {access is denied) an attempt to attach an auto named for file "path" a database with the same name exists, or specified file cannot be opened, or it is located on UNC share"
And if I attempt to add a connection choosing the "Microsoft SQL server" option in the choose data source window:
"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 the the instance name is correct and that the SQL is configured to allow remote connections..."
The only reason I want to connect visual studio to the database is because VS doesn't allow me to import text files. I have imported a text file into a DB from SQL server management studio and I want to connect it to VS. I've turned off UAC in windows 7 and I have file permissions to the mdf file.

Old question, but just to provide an answer for visitors from Google, the problem is not related to file system access (although Administrator accounts should have full privileges to the folder containing the mdf and log files). The solution is that SQL Management Studio needs to be opened using "Run As Administrator". The elevated permissions will allow SQL Server (or SQLExpress) to attach the older mdf file and update it. Once the db is attached, you can access it in Visual Studio by adding a database connection through the Add New Item->Data->ADO.NET Entity Data Model wizard.

Related

setup project for visual studio application using advanced installer with local db data is retrieved but not saved in db

I am using advanced installer (simple) to create the setup project of a GUI i am making in visual studio. upon installation, it is possible to read data from the databse i.e the records that are already added can be read but as i try to save data in databse that function is not working and the application stops working. i think that the connection string is right that is why iam able to read data from it but why cant i update data. plz help.
the databse is is service-based local database
This might happen if you have the database stored in the same install location as your application binaries. Usually that is a folder under Program Files.
You're application cannot write under this location when running as a standard user, and it should never write/store data in that location.
If you're not using the Application Data folder to store your database, I suggest you update your app to do so, this should solve your problem.

Writing a flat file in SSIS succeeds if run from VisualStudio, fails if run from the Integration Services Catalog

I have an SSIS package that does a Bulk Insert, then executes a SQL Task, and then finally writes some database data to a flat file on our network. The package runs fine if I run it from Visual Studio 2012. However, if I deploy the package to the Integration Services Catalog on a 2012 SQL Server and run it from there, the Bulk Insert and SQL Task run fine, but when the package tries to output to the flat file, I get these error messages:
Cannot open the datafile "\\nyfil006\Projects\Accounting\CostRecovery\Cafe de Novo\HospitalityCharges.csv".
HospitalityCharges Flat File failed the pre-execute phase and returned error code 0xC020200E.
I'm able to output the System::UserName to an errorlog, and it's what I think it should be: an account that has full permissions to the folder in the flat file destination (and its parent folders). I've tried creating a blank version of HospitalityCharges.csv, and DelayValidation is set to True for the Data Flow Task that outputs the flat file. My system admin has granted Network Service permissions to the folder as per this link and this link, but that doesn't help. I've also made the connection string an expression as described here. We've also created a mapped drive and used that for the Destination Connection String instead of a UNC path. No joy. Does anyone know why this is happening?
Another note: if I change the flat file destination to point to the C: drive, the package runs fine, whether I run it from Visual Studio or from the Integration Services Catalog.

Move documents to SharePoint 2013 using SSIS WebDav

I have an SSIS package that calls a .jar that exports a file from one system to a specified file path. For my filepath I use \sharepointserver\davwwwroot\library. The problem is I have to have an RDP session open and maintain my file server connection in order for this to work. It will fail without the RDP session and even the davwwwroot connection times out, requiring me to logoff, back on and browse again.
How can I get this process to work without the RDP session?

Is it possible to bypass DAO group/user security of old access database?

I'm trying to build new DB manager compatible with Windows 7 for old software which i don't have the code to. I am using 64bit Windows 7, and therefore cannot install the necessary DAO driver that was used to connect to the database.
Unfortunately, the database is protected using the DAO user/workgroup privileges. is there any way to extract the information from the database or bypass the security measures on that file?
You don’t mention what version of Access you have to work with.
If you have access 2010, or 2013, you can open the database using the workgroup security file with a shortcut.
2010
"C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE"
"c:\RidesDev\SkiRides\RidesXP\RidesXP.mdb"
/wrkgrp "c:\RidesDev\SkiRides\RidesXP\Rides.mdw"
2013
"C:\Program Files (x86)\Microsoft Office\Office15\MSACCESS.EXE"
"c:\RidesDev\SkiRides\RidesXP\RidesXP.mdb"
/wrkgrp "c:\RidesDev\SkiRides\RidesXP\Rides.mdw"
The above shortcuts are of course one line and each part being separated by a space.
Once you opened the database with the above shortcut then this specifies the workgroup security file. You will be prompted for user and password. Once you done this, then can from the Access file menu close the database. (Do NOT exit Access). At this point you can create a blank new 2010 accDB database. And then import all objects from the old mdb database.
Note the above works by you NOT exiting Access – this means you will remain attached to the security group. Since you remain attached to the security workgroup you are able to import all objects from the older mdb to the new accDB you just created. At this point I would then exit Access and then launch the newly created database.
The new database will thus be free of all security, and your exit + re-enter of Access and launching Access without the security group shortcut means you are opening the new database without workgroup security.
Above assumes you have the correct user + password logon with full rights to the database. If the database has startup code and forms that you can't by-pass, then you can create a blank database and again specify the above workgroup security file for the new database and that also would allow you to import the objects into your new blank database. The result should be an accDB file without any security.

Azure SQL Database Bacpac Local Restore

I've created a BACPAC backup of my Azure SQL Database using the "Export" option within the Azure Management Console.
Having downloaded this to my machine I'm a little stuck on how I can restore this to a local SQL Server instance. I came across the DacImportExportCli tool but couldn't find an example of a local restore.
Also if anyone has written a script that does this (so it can be scheduled) that would be awesome.
This can be done simply through SQL Server Management Studio 2012
Right click on the Connection > Databases node and select "Import Data-tier application..."
Select "Next" on the introduction step.
Browse, or connect to a storage account where backups are kept.
Try "SqlPackage.exe"
I needed to export a SQL Azure database and then import it into a local SQL 2008 R2 server (Note I am also using Visual Studio 2010). Microsoft certainly went out of their way to make this a painful task, however, I was able to do it by doing the following:
Go to this link http://msdn.microsoft.com/en-us/jj650014 and install the SQL Server Data Tools for Visual Studio 2010
This will install on your local drive. In my case here is where it put it: C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin
Browse to this via the command line or powershell
You are going to want to execute the SqlPackage.exe
Open up this link to see a list of all the parameter options for SqlPackage.exe (http://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx)
Here is my command line that I needed to execute to import a .bacpac file into my local SQL 2008 R2 server:
.\SqlPackage.exe /a:Import /sf:C:\mydatabasefile.bacpac /tdn:NorthWind /tsn:BINGBONG
/tdn is the name of the database you want your bacpac file to restore to.
/tsn is the name of your SQL server.
You can see all these parameter descriptions on the link from #5.
You can restore the BACPAC by using the client side tools. Videos are here:
http://dacguy.wordpress.com/2011/09/09/importexport-services/
The tools are available here:
http://sqldacexamples.codeplex.com/documentation
Seems my prayers were answered. Redgate launched their SQL Azure Backup tool for FREE today - http://www.red-gate.com/products/dba/sql-azure-backup/download
If you're using SSMS 2012, it is as easy as right-clicking on the Databases folder under a server in the Object Explorer and choosing "Import Data-tier Application...".
There is one bump in the road to watch out for: as of Mar 26 2013 (when I needed to find out how to do this myself), when you export a .bacpac from Azure, it will be downloaded as a .zip file, not a .bacpac file, and the file dialog that is opened by the Browse button in the import wizard will only show either *.bacpac or *.* in the file filters, implying that .zip is not supported. However, if you change the filter to *.*, select your downloaded .zip, and click Next, the wizard will proceed normally.
Here's a script to restore a bunch of bacpac files at once:
Bulk Restore bacpac files local
cd [FOLDERPATH]
$goodlist = dir
cd 'C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin'
foreach($i in $goodlist){
$name = $i.Name;
$namer = $i.Name.Substring(0, $i.Name.length - 7);
.\SqlPackage.exe /a:Import /sf:[FOLDERPATH]\$name /tdn:$namer /tsn:[SERVERNAME]
}

Resources