My problem is exactly as described in title, but I am not familiar with MS Access, and I'd like to avoid interacting with it at any cost.
I have stumbled upon a point of sale (POS) system, which is built on MS Access. MSAccess Runtime 2003, to be specific. It uses a couple of .mdf files, which reside in a shared folder on the same network, and there are, at the moment, 2 POS computers, working with the same database simultaneously. SQL Server 2008 Express instance is running on server, but it only lists the default databases. Here's part of POS config, running on server machine:
DBConnString=DRIVER=SQL Server;SERVER=(local);APP=Microsoft® Access;UID=sa;PWD=;DATABASE=DB_name
Systemfolder=C:\Kasse
Systemfolder here is where the .mdf files are stored. On client PCs, it is a path to folder, shared by server.
There is also a management program, which, when set up as client, is launched like this:
"C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE" c:\kasse\Kontor\TSKontor.mdb /Runtime /WrkGrp c:\kasse\Kontor\SYSKONTOR.MDW
It also has the same connection string as named before.
None of this is locking out other clients.
When I attach said MDF file to server in SSMS, I can use the database as intended, but POS program sometimes complains about locked files. I have detached them, and POS is now working as it did before.
Can someone suggest, how I can attach this database to SQL Server, without locking .mdf files? Is attaching the only solution?
Related
I'm not an expert with TSQL so have patience with me please. So recently I was doing a project in TSQL on my local server using SQL Server 2008 R2 Management Studio. I was reading my files from a temp file on my C: drive and bulk inserting them into tables at the time.
Then I went and moved to a regular server instead of my local server on my machine.
It took me a bit to realize that I no longer had access to my local machine folders and files, and that is causing me issues.
I've read that one solution is to create a mapped drive on the server, but this is not an option for me.
So my question is what are other options for me? Could I use UNC paths to access my files or anything else?
The files I want to access are regular text files that are comma-delimited and newline terminated.
(I saw somewhat similar questions to mine, but there's seemed server specific or specific to their particular issues. Also none of their questions were answered.)
Actually a mapped drive won't work either because the account SQL runs under by default (local system if I recall) will not have network access.
So, the more reliable way to do this is definitely with a UNC path BUT there is more! (I've done this several times when I've needed to move database backups and log backups across servers for mirroring).
How?
On the SQL server machine AND the other server that will host the share, create a new user (same username and password on both machines) - assuming your not using AD. The user needs not be in any groups at all other than the users group but it must be called the same in both servers and the password must match.
On the SQL server machine change the account that SQL SERVER is running under. This is done in the SQL server configuration tool. Do not try to do this yourself via windows services. Choose the user that you created in no 1 above. Note you have to enter the pw. Restart SQL after you've changed it and verify SQL still runs fine. It should run just as before but now is running as a particular user with all the permissions of that user (which actually are very limited anyhow, but at least the user can access network resources).
On the remote server, make sure the new user has NTFS permissions on the folders that will host your share. Read/write perhaps or just read if SQL is only reading data.
On the remote server, create a share pointing to the appropriate folder that you set permissions for above. Make sure if you're using share permissions that the new user also has permissions on the share (not just on NTFS on the drive).
Once all of this is setup, your SQL scripts simply use the UNC path that points to the remote share and since SQL is running "as" a user with access to that share, SQL will see the files just fine!
If I create a new MVC4 Web Application with the Internet Application project template (which uses forms authentication) then, when I run it the first time and click on Register, the call to context.Database.Exists (in the InitializeSimpleMembershipAttribute filter) correctly detects that the database file does not exist, and ObjectContext.CreateDatabase is called, creating the dbf and ldf files in the App_Data folder.
If I then delete the dbf and ldf files and run the app again, the call to context.Database.Exists returns true, despite the fact that the database file is gone. This behavior seems to be persistent: Once ObjectContext.CreateDatabase has been called, some magic seems to remember that the database "exists", even if the physical file is gone and even if I restart the PC.
Ok, so I assume that something in SQL Server is remembering the existence of the database. So I've installed and run SQL Server Management Studio. But the only thing that appears under the Databases folder under the \SQLEXPRESS node is the System Databases folder. I see no sign of my database file connection.
What's this all about? Why does context.Database.Exist return true, and how can I convince it to return false if the database file is gone? And why don't I see some evidence of the database connection in SQL Server Management Studio?
Bob
You can remove the database by deleting it from your LocalDb instance. Using SQL Managment Studio connect to "(LocalDb)\v11.0".
I use a .mdf file as my database. I also used Linq-to-SQL connection.
At first, my application can add and display the data in the .mdf file correctly. But when I try to see the data by clicking the .mdf file directly and from the table, the database is empty.
I've set the .mdf file and the .dbml file Copy if newer, but still nothing.
Please help me and thank you for your help.
I bet your connection string contains
AttachDbFileName=somefilename.mdf
The whole User Instance and AttachDbFileName= approach is flawed - at best! Visual Studio will be copying around the .mdf file and most likely, your INSERT works just fine - but you're just looking at the wrong .mdf file in the end!
If you want to stick with this approach, then try putting a breakpoint on the myConnection.Close() call - and then inspect the .mdf file with SQL Server Mgmt Studio Express - I'm almost certain your data is there.
The real solution in my opinion would be to
install SQL Server Express (and you've already done that anyway)
install SQL Server Management Studio Express
create your database in SSMS Express, give it a logical name (e.g. YourDatabase)
connect to it using its logical database name (given when you create it on the server) - and don't mess around with physical database files and user instances. In that case, your connection string would be something like:
Data Source=.\\SQLEXPRESS;Database=YourDatabase;Integrated Security=True
and everything else is exactly the same as before...
I developed an Access 2003 application that is connected to SQL Server.
My problem is that I developed the software on my server, and the application runs on the client network on a different (identical) server.
As a result my executable file (Aka. .ADE) does not open on the client's computer, because of bad SQL Server connection.
My solution so far was to open the application file (.ADP) on the client's computer, changing the connection path from there and then creating there the executable file.
Now my client has only Access runtime environment, so I cannot do such thing.
I wonder if there is a way to determine the connection in an ADE file this way.
(I know I can change it through VBA, but when the connection is initially false, I don't even get to the VBA code stage.)
In the interest of keeping things simple, I'll say you need to set up a testing environment you control that mimics your client's environment. For instance, if they have a sql 2008 server named "SQL1", then you should install sql 2008 express on your machine, and rename your machine to "SQL1" so you can test. You'd also need to copy the schema of their database tables and put that same schema in your own test database, and fill it with test data that is similar to theirs. And you'll want to create duplicate logins as well.
With all that in place, I wouldn't think you'd need to update anything. Just copy the ADE file over to your client when you're done making changes. You could try to code your way though this scenario, but I've been there and done that. Having a test environment that apes your client's takes a lot of headaches out of the equation.
Subquestioning [2]
While copying Resource.mdf [1], I noticed that:
1)
It is possible to copy Resource.mdf without stopping SQL Server instance (I attached one having copied from running instance and it works after attaching) .
1a)
Should I understand that it as general possibility for all read-only databases or is it only in some versions (mine is 2008 R2 on Windows XP Pro Sp3)?
1b)
Conceptually, I cannot understand why a developing (Dev Ed) SQL Server on isolated/workgroup desktop Windows (in my case - XP Pro Sp3) should be stopped in order to copy a user-defined non-used (for ex., sample database) database.
1c)
When one should copy .LDF together with .MDF file and when copying .LDF can be skipped?
Why does read-only database have necessarily (transaction log? as I understood) file LDF?
2)
Resource.mdf (in my SQL Server 2008 R2 on default unnamed instance, Windows XP Pro SP3) is in
%ProgramFiles%\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\
and not in
%ProgramFiles%\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\Binn\ [2]
I am curious - Is the location differing due to SQL Server version, edition or Windows edition, version?
[1]
My question "how to see/script definitions of system views?"
how to see/script definitions of system views?
[2]
Martin Smith's answer to [1]
how to see/script definitions of system views?
If the database has auto_close turned on then the engine will close the file handle when the database is no longer in use. Express instances create databases as auto-close ON and this property is preserved when database is attached to a non-Express instance.
It is not true that you have to shutdown the instance to copy a database file. All you have to do is to relinquish the exclusive handle held by the SQL Server instance on the database files(s). This can be done by simply setting the database offline, do the copy, then setting it back online. (If I remember correctly) for databases that are read-only, the handle held by SQL Server allows for another processes to open a shared handle on the file. This is why
you can copy an online read-only database, and msqlsystemreource is read-only under normal operating mode.
Other questions:
1c) never. Always copy the MDF, all NDFs and the LDF(s). Even when there are recomendations to copy the MDF alone, ignore them and copy the LDF as well.
2) the resource databases are part of your binaries. They will be in the binn folder of your installation, same location as sqlservr.exe. The path will differ for each installed instance and you can change it during Setup.
And one last consideration: why do you touch the resource db? You are up for a world of pain, you may easily corrupt your instance if you manipulate resource db in any way.