Importing a .cvs file into a detached .mdf? - sql-server

I was asked to repost this question, due to the answers were not going the right directions.
I have a detached database similar to to Northwind.MDF I want to import a .CVS file into this MDF file. I have the mdf file as part of my Solution Explorer in vs2010 and I can look work with the data, just no way to import. In vs2010 I can use the Server Explorer and connect with no problems. the connection string looks like this:
Data Source=.\SQLEXPRESS;AttachDbFilename=D:\ASPX\sdb1\customer.mdf;Integrated Security=True;User Instance=True
When I try to use any tool outside of vs2010 I cannot connect. Non of the sqlserver tools connect and give me an access denied, even when I try to attach the file from within Management Studio.
TITLE: Microsoft SQL Server Management Studio
Attach database failed for Server 'STEPHANS-PC\SQLEXPRESS'. (Microsoft.SqlServer.Smo)
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
Unable to open the physical file "D:\ASPX\sdb1\customer.mdf". Operating system error 5: "5(Access is denied.)". (Microsoft SQL Server, Error: 5120)
This should not be this tuff to import data from a CSV.

You have to connect to your user instance database using an special connection string.
An user instance database is a sql express database based upon an mdf file (just what you have).
This link explains how to connect from SSMS to your User Instance Database:
How to: Connect to a User Instance

Related

Cannot import data from Access to MS SQL Server

I am trying to migrate a vb.NET project from an MS Access database to MS SQL Server, and have been following a tutorial I found here to do so. I did this, but got a problem where I could read data from the SQL Server database when running my project, but could not insert/edit data using the project.
Any data I tried to manipulate only worked on the Access database, and didn't have any affect on the SQL Server data (I also tried vice-versa, adding data using SQL Server but this couldn't been seen in my project).
So I decided to try again, deleting the Access and SQL Server databases, and using the backup database to import the data from. However, this now is not working, and I'm getting the following error message
Error 0xc020801c: Source - ~TMPCLP123581 1: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager "SourceConnectionOLEDB" failed with error code 0xC0202009. There may be error messages posted before this with more information on why the AcquireConnection method call failed.
(SQL Server Import and Export Wizard)
Exception from HRESULT: 0xC020801C (Microsoft.SqlServer.DTSPipelineWrap)
Does anybody know a fix for this? Or why I can no longer import data into SQL Server? (The image below shows the result of what processes were/weren't carried out)
I've fixed the issue now, guys.
I migrated it over using Microsoft SQL Server Migration Assistant for Access, and then changed the connection path and settings in my .ini file.
Then I created a new connection string, using string variables for each of the settings in the .ini file, and this replaced the initial Access database connection string.

Connecting to SQL Server LocalDB in Delphi

I have a .mdf database file, I want to connect to this file with ADOConnection and SQL Server LocalDB as provider
My connection string looks like this :
Data Source=(localdb)\v11.0;Integrated Security=SSPI;AttachDbFileName="MyMDFFileAddress";
But when I try to connect, this error is shown:
An attempt to attach an auto-named database for file "MDF File"
failed. A database with the same name exists, or specified file
I have tried many ways, but always the error above is shown!
I have Installed SQLLocalDB and SQL Server Native Client 11.0
On my machine I can connect to my own created instance on localDB and my database, but when I want to connect this file in another machine and use default instance and AttachDbFileName, that error is shown
I copied the .mdf file to default instance folder of LocalDB and tried to connect, but the same error is shown
I searched a lot but found no correct answer !
I'm using Delphi XE 6
Did you try this?
Data Source=(localdb)\v11.0;Integrated Security=True;AttachDbFileName=|DataDirectory|\"MyMDFFileAddress.mdf";Initial Catalog=YourDataBaseName;providerName="System.Data.SqlClient"
Is there DataBase instance (v11.0) in another machine?
Open command prompt and type to verify:
sqllocaldb info

SQL Server 2008 connection error

Currently my project is running, however I connect same project database with SQL Server Management Studio which shows error
Failed to retrieve data for this request.
(Microsoft.SqlServer.Management.Sdk.Sfc)
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or
batch. (Microsoft.SqlServer.ConnectionInfo)
CREATE FILE encountered operating system error 32(The process cannot
access the file because it is being used by another process.) while
attempting to open or create the physical file 'gg.mdf'. (Microsoft SQL Server, Error: 5123)
How can I fix this error?
You're probably creating a database with the same file names (.mdf) or a database which already exists on the SQL server.
I'm not sure what type of project you are talking about but try to change the physical file names of the database or removing the existing database from the server.

SQL Server Management Studio: Database Attachment Failed

I have publish my website in IIS7. It is running in DefaultAppPool. The Identity of this app-pool is set to LocalSystem. The IIS is running and I can run the application from IIS without any problem.
Now I want to attach the database placed in inetpub's application folder:
C:\inetpub\wwwroot\EMSApplication\App_Data\ASPNETDB.mdf
I have added new logins in the SSMS which are: NT AUTHORITY\NETWORK SERVICE and IIS APPPOOL\DefaultAppPool.
But when I am trying to attach that database in the SSMS I am getting follwoing error:
TITLE: Microsoft SQL Server Management Studio
Failed to retrieve data for this request.
(Microsoft.SqlServer.Management.Sdk.Sfc)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&LinkId=20476
------------------------------ ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or
batch. (Microsoft.SqlServer.ConnectionInfo)
CREATE FILE encountered operating system error 5(Access is denied.)
while attempting to open or create the physical file
'C:\inetpub\wwwroot\EMSApplication\App_Data\ASPNETDB.MDF'. (Microsoft
SQL Server, Error: 5123)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.00.5500&EvtSrc=MSSQLServer&EvtID=5123&LinkId=20476
------------------------------ BUTTONS:
OK
By default Microsoft SQL Server Management Studio works against a Parent Instance of SQL Express, not your User Instance. A user instance is a separate instance of the SQL Server Express Database Engine that is generated by a parent instance. User instances allow users who are not administrators on their local computers to attach and connect to SQL Server Express databases. Each instance runs under the security context of the individual user, on a one-instance-per-user basis. Here is a manual from msdn How to connect to a User Instance.
I was able to do that running Management Studio As Administrator.
I had same problem.your .mdf and .ldf files don't have necessary permission.
you should add your windows account in both .mdf and .ldf files and give it full control permission.
Now you can attach your database successfully.

Can't connect to my own MDF file. Cannot open user default database. Login failed.Login failed for user... and other errors

SQLSEXPRESS service IS running!!
I have I program I wrote some time ago and it works. It was written in MS Visual Studio with local MDF file.
How is it possible to edit this file from Microsoft SQL Server Management Studio? I don't see this file in the list of globally connected databases.
If I try to attach this file with Visual Studio Wizard, I get message that such database already exists, but when I set arbitrary logical name, I get sharing violation.
How to reach MDF file?
EDIT 1
Now I found that my program also stopped to work.
The summary of results of different attempts to reach MDF file:
Program itself System.Data.SqlClient.SqlException (0x80131904): Cannot open user default database. Login failed. Login failed for user <username>. (windows user)
Visual Studio, Data source = Microsoft SQL Server, Logical Name = "" Error message: An attempt to attach an auto-named database for file
<filename> failed. A database with the same name exists, or
specified file cannot be opened, or it is located on UNC share.
Visual Studio, Data source = Microsoft SQL Server, Logical Name = SOMENAME Error message Unable to open the physical file <filename>. Operating system error 32: "32(The process cannot access the file because it is being used by another process )".
Cannot attach the file <filename> as database ‘SOMENAME’.
Visual Studio, Data source = Microsoft SQL Server Database File, Windows Authentication Error message: Cannot open user default database. Login failed. Login failed for user <username>.
Visual Studio, Data source = Microsoft SQL Server Database File, SQL Server Authentication Error message: Failed to generate a user instance of SQL Server. Only an integrated connection can generate a user instance. The connection will be closed.
Microsoft SQL Server Management Studio, Attach Database Error message: Unable to open the physical file <filename>. Operating system error 32: "32(The process cannot access the file because it is being used by another process)". (Microsoft SQL Server, Error: 5120)
MDF files are not intended to be used directly.
You may use them only through and with the help of SQL Server Engine.
Try this:
1- Create a database with the same name to mdf file.
2- Stop sql service
3- Go to the Data Carpet where is all mdf files and ldf , copy your original mdf file y replace.
4- Start the service
5- See in the management studio if the database still online there you go.
A .MDF database cannot be "opened".
It must be attached to an existing (and running) SQL Server instance.
If you have SQL Server Management Studio running, open a connection, and right click on databases. Choose "Attach" and point to the .MDF file. This will (attempt to) attach the database to the master database. If it works, the database will be visible in SSMS.

Resources