The problem is when I try to install my setup in other PC it gave me errors of database file .mdf
How can I make my setup goes with database auto
T tried a lot of ways to create my setup. Yes I created it but it work just in my PC not in other.
Here is my last connection string:
ReadOnly con As New SqlClient.SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True")
could not open new database 'C:/............./database.mdf' create database is aborted.
an attempt attach an auto-named database file 'C:/............./database.mdf ' failed.A database with the same name exists, or specified file cannot be opened ,or it is located on UNC share.
file activation failure, the physical file name 'C:/............./database_log.ldf' may be incorrect.
the log cannot be rebuilt when the primary file is read-only.
Related
I am struggling with an error when using create pluggable database from command. My config is:
HOST_A - source CDB with couple of PDBs with ASM
HOST_B - destination CDB with couple of existing PDBs with ASM
I would like to create a new pluggable database on HOST_B using dblink to HOST_A and "create pluggable database X from dbLink" statement, however I'm getting this error:
ORA-65169 Error encountered while attempting to copy file -- path to .DBF file on HOST_A
ORA-17628: Oracle error 19505 returned by remote Oracle server
ORA-19505: failed to identify file ""
I have checked above path to .dbf file and owner on HOST_A - it exists and has correct owner. Also, HOST_B has enough space to create new snapshot. What makes that even more weird, is that I have very similar HOST_C with same init parameters and it works without any problem.
I noticed on HOST_B oracle has copied these files and placed them under valid ASM mount point with correct name etc, however create pluggable database still fails.
Any ideas?
I'm attempting to get SQL Server Service Broker working across database instances and an at the stage of copying certificates (from initiator to target and vice versa). I can back up the certificate to a file but once created I can't open the file or copy it to any other location. If I try and open the file I get a message box with the title "Invalid Public Key Security Object File" and the message "Access is denied.".
The server is within the local domain and is running Windows Server 2008 R2 Enterprise with SP1.
This works (but I cannot do anything with the file):
BACKUP CERTIFICATE UserCertificateB TO FILE='C:\Certs\UserCertificateB.cer';
This doesn't work:
BACKUP CERTIFICATE UserCertificateB TO FILE='\\localmachine\Certs\UserCertificateB.cer';
Error message is:
Msg 15240, Level 16, State 1, Line 2
Cannot write into file '\localmachine\Certs\UserCertificateB.cer'. Verify that you have write permissions, that the file path is valid, and that the file does not already exist.
I can back up the certificate to a file but once created I can't open the file or copy it to any other location.
Yes, the access is restricted to the SQL Server service account. Grant permissions as appropriate on the file, using an administrative account. Use icacls.
Cannot write into file '\localmachine\Certs...'
You are doing a 'double hop' so it requires Kerberos constrained delegation. Contact your network administrator to set it up properly for you.
I know this is an old question, but maybe this answer will be relevant to others that may find the same issue.
If it shows the error ‘Msg 15240, Level 16, State 1, Line 8
Cannot write into file 'C:\tmp\cert\MY_TDE_CERT_KEY.PVK'.
Verify that you have write permissions, that the file path is valid, and that the file does not already exist.’
It is because the script has to be executed on the server and not the local computer connected to the server.
Once the SQL script executed in the server then the files will appear in the selected folder in the server (must create a local directory).
Error (the image shows the path of the local computer, it was the wrong path, must be in the server):
After executing in server
Learned this from Microsoft:
"The path is relative to the SQL Server instance. The path needs to be setup on the machine hosting the instance."
I am trying to programmatically create and connect to an application specific LocalDB database. I would like to do this by specifying the file name of a .MDF file only, ideally without specifying an instance name or a name for the database that gets registered anywhere.
The database is to be accessed from some unit tests so it will only be used for a brief time before being deleted. My current approach creates the .MDF file correctly but also registers the name with the default instance which I would like to avoid given the temporary and 'non-singleton' nature of the database instances.
Is it possible to do what I am trying to do, or have I misunderstood how LocalDB works?
LocalDB automatic instance with specific data file
Server=(localdb)\v11.0;Integrated Security=true;
AttachDbFileName=C:\MyFolder\MyData.mdf;
Update
This can be used with the Deployment area in your .testsettings file. You just need to check 'Enable deployment' and add both the .mdf and .ldf files to 'Additional files and directories to deploy'.
You can then simply use the connection string above, and the test runner will take care of moving your data files to an appropriate temp folder for you.
Chrisb's answer got me on the right lines to solve this, but I noticed that the database remained attached to the default instance in LocalDB even after the connection had been closed. I read that this might eventually be purged after a few minutes but in my case this was too long as the file was located in a temporary directory used by MSTest and had to be closed in time for the cleanup at the end of the test run.
The solution was to use a connection string similar to https://stackoverflow.com/a/26712648 and a detach process similar to https://stackoverflow.com/a/6646319 immediately after I had finished using the connection.
Creating the MDF file in the first place could be accomplished by connecting to the automatic LocalDB instance, executing CREATE DATABASE and then using the same detach method. By using the file name for the database name, which is allowed in LocalDB due to the much longer names permitted, I ensured beyond reasonable doubt that the database name will not clash with anything else on the computer even during the short period it stays attached.
I've been working on a CodeFirst POCO WPF project and I want the database to be LocalDB. I've used migrations (add-migration and update-database commands in the Package Manager Console window) to generate my database and tables. I've set my config file to have the following connection string:
<add name="MyContext" connectionString="Data Source=(LocalDB)\v11.0;Database=MyDatabase;Integrated Security=True;" providerName="System.Data.SqlClient" />
With that connection string, after I call update-database in the console, it creates the database and all my tables properly, however it puts the MDF file in the root of the currently logged in user. That is the behavior I'm trying to change. I'd like the DB created in the application's folder. How do I do that?
I've tried adding "AttachDBFileName=|DataDirectory|\MyDatabase.mdf" to the connection string, but after running update-database I get this error:
A file activation error occurred. The physical file name '\MyDatabase.mdf' may be incorrect. Diagnose and correct additional errors, and retry the operation.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
I get the same error if I try "Initial File Name" instead of AttachDBFileName. It seems like this would only work if the file already exists? But I'd like the file to be auto generated when the user first launches the app, and have the file exist in the same folder as the application. How do I go about doing this?
-shnar
This is because the default location for the data file using DataDirectory is in Program Files for Desktop applications. To modify Program Files sub-directories requires that the program run as administrator or that the directory be given the appropriate write-access. See AppDomain.SetData to set the DataDirectory macro to the actual %AppData% directory. Its against Microsoft Best Practices to create data files in Program Files and it usually unnecessary to do so.
I'm learning ASP.NET MVC 3 with Entity Framework Code First. I'm following a tutorial and I downloaded the corresponding solution for testing on my local machine. Now, something I didn't understand very well is about the automatic creation of the database (if this one didn't exist yet on disk). The very first time I run the application, the database is created for me. That's ok.
Here is the section in Web.config
<add name="BlogContext"
connectionString="Data Source=.\SQL2008;Initial Catalog=CodeFirstMVC.mdf;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
But I have two problems:
1st. For testing purpose, I deleted the database on disk and run again the solution. I thought that the database would be automatically created but I was wrong: I got the error message below:
{"Unable to open the physical file \"c:\\Program Files\\Microsoft SQL Server\\MSSQL10.SQL2008\\MSSQL\\DATA\\CodeFirstMVC.mdf.mdf\". Operating system error 2: \"2(failed to retrieve text for this error. Reason: 15105)\".\r\nCannot open database \"CodeFirstMVC.mdf\" requested by the login. The login failed.\r\nLogin failed for user 'sa'.\r\nFile activation failure. The physical file name \"c:\\Program Files\\Microsoft SQL Server\\MSSQL10.SQL2008\\MSSQL\\DATA\\CodeFirstMVC.mdf_log.LDF\" may be incorrect."}
I noticed that if I changed the file name in my Web.config then the database is again successfully created. Can you explain me? Why do I have to change the database name to get it running again?
2nd. The database is created in the folder located in C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA. I would like to store my database in the App_Data directory. How can I proceed?
Initial catalog is not path to file. It is the name of database. AttachDbFilename is used to specify the file so your connection string should look like:
Data Source=.\SQL2008;Initial Catalog=CodeFirstMVC;AttachDbFilename=|DataDirectory|CodeFirstMVC.mdf;Integrated Security=SSPI
Where |DataDirectory| instructs SQL server to use local application data directory instead of global SQL Server data directory. Local data directory for web application is App_Data.
Edit:
I just noticed that you are probably using full SQL server instead of SQL server express. As I know creating database in App_Data automatically is feature of SQL server express. That also explains first error because SQL server created database called CodeFirstMVC.mdf and stored the database in its global data directory within CodeFirstMVC.mdf.mdf file and transaction log in CodeFirstMVC.mdf.ldf file. It also registered that database internally. By deleting files you didn't remove database from SQL server. You just break its functionality but SQL server still believes that the database exists. That is also reason why you have to change the name to make it work.