TSQL attach db that is currently in use - sql-server

I have a shaprepoint system and I cannot attach the sharedservices_db
It is in use when I attempt to attach it.
I have stopped that web server associated with sharepoint data but no change in db is in use.
Any ideas?

Do a select against sys.master_files for the file name that it's giving you grief about. From there, you can see what database is using that file.
But of greater concern is that you're not trying to attach a database that has been attached. You're trying to attach one that's still active. Take five minutes and re-evaluate what you're doing before you have an accident.

Related

While trying to create entity data model, I get authorization exception

I set up my visual studio to always run as administrator.
When I create a new Entity Data Model, and try to point to the data source to a specific database, I get the error "Login failed. Log in is from an untrusted domain...."
I think that since I set VS up to run under administrator, Administrator needs access to at least one database, so I set that up as well.
But I am still getting the same issues.
See screenshots.
There is a bug with Microsoft.
The server name dropdown box doesn't always list the right servers.
It was listing a server that did not exist.
Somehow, it gets this information, from somewhere--I don't exactly know how--but I did have the posted server name on a different machine at one point in time.
I clicked on the ddl and picked the first one, assuming it found my server, but in fact the server did not exist.
I had to copy paste this in: DESKTOP-DLASSIT\SQLEXPRESS
Because that was the real name of my server.
Then, it worked...

Logging to windows application event log

Hi this is basically what I want to do in sql server management studio.
Whenever any user tries to delete or update the data in the table, it needs to be logged into the Windows Application event log.
Is there anywhere I can reference how to do this? I can't find anything.
Thanks
Full Question:
As the Products table is a very important table, the company wishes to track selected changes to the
table. Whenever any user tries to delete or update the data in the table, it should be logged into the
Windows Application event log. However, there is no need to undo the changes as it may be a
legitimate change.
You should use SQL Server Audit for that. When you create a server audit, specify audit destination to be Windows Application Log. For more information, see CREATE SERVER AUDIT (Transact-SQL). Since it is a school assignment, I believe it will be the best for you to try write it yourself. Good luck!
Realize this is an old question but I recently had to deal w/something like this again myself. I used the following (although you may/may not run into permission issues depending on how you run it):
EXEC master..xp_logevent 50001, 'My log message here...', 'INFORMATIONAL'
More info here

Shared Access 2010 database is in an inconsistent state

I have a shared accde file on a network drive. Occasionally we will have an inconsistent state problem. The error message appears below. It seems to be associated with network connection interruptions for even one user. We have an example when a user unplugged the Ethernet and switched automatically to wireless and other examples where users have left the database open overnight, perhaps when a machine hibernates.
Once this happens the one user cannot work and no one can open the accde file. Other users who have the database open can continue to work.
After the problem occurs it remains until everyone closes the database. At that time it completes whatever recovery it requires and all users can get back in.
This was disruptive when we had six users in one room. Now we have 17 in two cities and a few work-from-home users. It's becoming intolerable.
The obvious answer is to move away from Access. We're working on it but it's a long way off. In the mean time I would appreciate any advice.
Is there a way to prevent the problem entirely?
Is there a VBA way to detect the problem in the instances that are not showing the error message?
Is there something I'm not thinking of?
What would you do?
Error message:
Microsoft Access has detected that this database is in an inconsistent state, and will attempt to recover the database. During this process, a backup copy of the database will be made and all recovered objects will be placed in a new database. Access with then open the new database. The names of objects that were not successfully recovered will be logged in the "Recovery Error" table.
The solution that Microsoft gives is Splitting the database, which just means to put the data elements on a shared server, and everyone has their own copy of the front end.
This might cause problems if that front end needs to be updated (e.g. additional forms). Details here:
http://answers.microsoft.com/en-us/office/forum/office_2007-access/microsoft-office-has-detected-that-this-database/3fb41c70-f7ba-41dd-a847-e62203071466?auth=1
Check the row count in the tables, the tables most likely have large amounts of data creating latency on the read and write queries, causing the locking.
Archive older data and keep the database small and neat, perhaps create referenced databases for archived information
I gather that your MS Access database is getting corrupt when up put it on a shared drive. A Microsoft Access database may get corrupt when in a multi- user environment. Here are the workaround that you can use in order to fix it.
Step 1: Run Command Prompt as Administrator
Click on the Windows icon and type Command Prompt. Then right-click on the Command Prompt and choose Run as administrator option.
Step 2: Execute Compact and Repair Database Command
In the command prompt window, type the following command and then press ‘Enter’.
msaccess <database file name> /compact
In the command, replace <database filename> with database path. For instance,
msaccess "C:\Program Files\Reports.mdb" /compact
This will start the process to compact and repair the faulty Access database file.
Otherwise, You can check out this thread for an alternative solution : https://dba.stackexchange.com/questions/71906/ms-access-mdb-ldb-database-corrupted/171275#171275

"Cannot open user default database. Login failed." after installing SQL Server Management Studio Express

I have a database in a local file that is used by a program. The program has limited functionality and I needed to run some quick queries. I installed SQL Server Management Studio Express 2005 (SSMSE), connected to the SQL Server instance, attached the database file, and ran the queries. Now the original program will no longer connect to the database. I receive the error:
Cannot open user default database. Login failed. Login failed for user 'MyComputer\MyUserName'.
I've gone back into SSMSE and tried to set the default database. I've opened up Security, Logins, BUILTIN\Administrators and BUILTIN\Users. Under General, I have set the default database to the program's database. Under User Mappings, I made sure the database is ticked and that db_datareader and db_datawriter are ticked.
The program uses the connection string:
Server=(local)\Instance; AttachDbFilename=C:\PathToDatabase\Database.mdf; Integrated Security=True; User Instance=True;
I know jack-all about database administration. What else am I missing?
This may not be answering your question specifically, but it may help others with similar issue caused by different problem
In my case the problem was my user is defaulted to a database which is not accessible for any reason (can be renamed, removed, corrupted or ...)
To solve the issue just follow the following instruction
Try to login again on the login page there is other tabs select
"Connection Properties".
under the tab locate "Connect to database" and select an existing database you have access to like tempdb or master
Once you are connected to the SQL Server Instance execute the below TSQL to assign the login a new default database.
Use master
GO
ALTER LOGIN [yourloginname] WITH DEFAULT_DATABASE = TempDB
GO
Alternatively once you connected change your default database name to master via UI
Article taken from :
http://www.mytechmantra.com/LearnSQLServer/Fix-cannot-open-user-default-database-Login-failed-Login-failed-for-user-SQL-Server-Error/
This problem manifested for me when I took my default db offline. Next thing I know I couldn't login. Switching to the Connection Properties tab and selecting the drop down to change the database I want to connect to also failed.
It let me in right away once I manually typed master as the db I wanted to connect to (on the Connection Properties tab).
First, try to isolate your problem:
Take a backup of the file! Some of the steps below can, apparently, in some circumstances cause the file to vanish.
Are you sure you are connecting to the same instance through Management Studio as the program is?
If possible, try to shut down the instance that you are not expecting to use.
Set the user's default database to master and try to make the program logon.
Try to login as the user through Management Studio - since you have integrated security, you should open Management Studio as the program's user.
Are you using "User instances" - perhaps without knowing it? If so, this may be helpful: http://blogs.msdn.com/b/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio.aspx
I haven't worked much with files being attached in the way your program does - but you write that you attached the DB in the Management Studio as well. Have you tried detaching it there before running your program? Perhaps you are seeing the Management Studio and your program competing for exclusive access to the MDF-file?
EDIT: I added point 6 above - this is new in my own list of TODOs when troubleshooting this type of Login failed. But it does sound a lot like what you're experiencing.
EDIT2: In the first edit, new item was added to the list. So the numbers in the comments doesn't correspond with the numbers in the answer.
I finally figured this out, and my situation is different than every other I've read about tonight.
I had restored my database from a backup. I knew that there was a particular login user that I had been using, so I created that user in SSMS. However, there was already a user by that name under the database that had come in with the backup.
Since I had screwed around so much trying to fix this, I wasn't able to delete the user under the DB easily. I deleted the database and restored again. Then:
Delete the user under the Databases->[my database]->Users
Create the user again in Security->Logins (not under your DB, although that probably works too.
Go to the newly created user. Select properties. Then under User Mappings, tell it to make your database the default. Give it read and write access.
Summary: I had two users. One that came with the DB, and one that I had created. Remove the one that came with the DB and create your own.
First click on Option>> Button of “Connect to Server” Prompt.
Now change the connect to database to any existing database on your server like master or msdb.
More Details
https://blog.sqlauthority.com/2008/11/04/sql-server-fix-error-4064-cannot-open-user-default-database-login-failed-login-failed-for-user/
I've also had this same problem, it turned out that I was trying to access the built in membership classes (in a view), and that .Net was trying to create the database in the App_Data folder:
#Membership.GetUser().ProviderUserKey
This will trigger the system to try and create a database based in the built in membership system, which may not be the way your system is setup.
I had a similar problem had to simply download SQL Express Utility that is capable of starting User Instances. SSEUtil is a tool written by the Visual Studio team to help troubleshoot User Instance issues, you can read more about it in the read me file that is installed with the utility.
http://www.microsoft.com/downloads/details.aspx?FamilyID=fa87e828-173f-472e-a85c-27ed01cf6b02&DisplayLang=en.
Hope this will help.
In my case I had to set "connect to any database" right path:
On your instance, go to Security , then to Logins.
Right Click on there, you will see properties and you should click on Securables.
There it give possibility to connect to any database.

SQL DTS Database Copy Fails

Hey All, I have been working on this problem for a while and the usual google searches are not helping :(
I have a production database in SQL 2000. I want to copy it over the top of a training database to refresh it. I want this to be something that is scheduled to happen once a week to keep the training database up-to-date.
I have a DTS job created for doing this. Within that DTS job I have a single "Copy SQL Server Objects" task. That task is set up to:
Create all copied objects
Drop destination objects first
Copy data
Replace existing data
Copy indexes, triggers, primary and foreign keys
Copy all user tables, views, functions and stored procedures.
When I run this DTS package (in pre-production for testing of course) it gets to 99% done and throws the following error:
Step Error Source: Microsoft SQL-DMO (ODBC SQLState: 42S02)
Step Error Description:[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.vwEstAssetStationAddress'.
Step Error code: 800400D0
Step Error Help File:SQLDMO80.hlp
Step Error Help Context ID:1131
My searches on the net didn't provide much help. There are reports of these errors getting hit, but none seem to match my circumstances. One suggestion I found was the the sysdepends table had become corrupted, making the DTS job run its scripts in the wrong order. Howeever, I ran the following script to correct that table and it still throws the same error:
USE master
GO
ALTER DATABASE [DATABASE NAME]
SET SINGLE_USER
GO
USE [DATABASE NAME]
GO
DBCC CHECKTABLE('sysdepends',REPAIR_REBUILD )
GO
USE master
GO
ALTER DATABASE [DATABASE NAME]
SET MULTI_USER
GO
I have also seen that having different object owners can cause this error. But I have confirmed that the objects are all owned by the dbo user in this case.
Any suggestions?
I feel stupid, but am posting the answer I just found for posterity (and so all you helpful fellows can stop stressing on my behalf.
Even though I had selected all the user tables, views, stored procedures and user defined functions to copy, I hadn't selected "Include all dependant objects". I had assumed that if you selected two objects to copy, and one was dependant on the other, SQL would always do them in the correct order. Aparrently not. Selecting this little check box made all the difference.
Thanks again to those who helped with suggestions
Somehow the dbo.vwEstAssetStationAddress table is not being found by your DTS package. Unfortunately, the message doesn't say if it was on the source or destination that it couldn't find it.
What are the exact steps, in the order that you have them in your DTS package? I'm assuming that the list of the task items above is not in order. I know this not an answer, but it looks like we are going to need a bit more information to help you further.
Thanks for the response hectorsosajr.
the object aparrently causing the error (dbo.vwEstAssetStationAddress) is a view that references 2 underlying tables. I have tested querying the view, as well as running the SELECT statement that defines it, on both the source and destination databases and it works fine.
The database object copy task in DTS doesn't allow you to specify the order it transfers things in. As far as I understand it, it uses the sysdepends table to determine the requisite order of events.
I was trying to avoid doing it via backup / restore. There are some users of the database that are SQL Server accounts (not Active Directory). This becomes a pain in the but if you need to do it from one server to another as you have to drop those users and recreate them.
Sounds like it is trying to create a stored procedure/view based on a view that doesn't yet exist.
Why not just backup and restore the database under a different name? (if it wasn't production, I would say detach, copy and re-attach). You can do all that under the control of T-SQL.
See if this link helps you find your dependency issue.
I've run another test to try and isolate this. I removed the mentioned view from the destination database totally, then ran the DTS again. It failed with the same error. However, the view that aparrently is an invalid object name was recreated successfully. It seems that the error is coming from something trying to reference that view, but it doesn't actually stop the script when it hits that error.
Cade - I will check out that link. I will also try and establish what is referencing the view and breaking.

Resources