I recently installed and have been using Microsoft SQL Server Management Studio Express 9.00.4035.00 to manage a remote database on my hosts' SQL Server 2005.
Until now I had been using EMS SQL Manager 2011 Lite and that was working fine.
2 new rows where inserted into one of my tables this morning; one by a customer signing up for a service and the other as a test signup by me.
When I run a typical select query:
[Select top 20 * From tblNotary Order By ID Desc]
I don't see the the 2 most recent rows. But when I run the same query from EMS SQL Manager Lite I see the records.
I also verified when connecting using MS Access 2010 I see the 2 new rows in the table. I have checked and double-checked the connection settings and they match EMS.
Is there a setting or something obvious I am missing? Why can't I see the most recent record insertions? I am on a Windows 7 desktop machine.
The most likely reason is you are connecting to a different database than you expected. You can select ##servername to verify both queries are running against the same server.
If the records are stil being inserted as part of an open transaction and have not been committed, they are called "phantom" rows. You will not see phantom rows if your query runs at transaction isolation level read committed or higher. It may be that EMS SQL Manager Lite is running at read uncommitted, in which case it will include phantom rows in the query.
Sometimes connection strings are a tricky thing. Run this to double check:
select ##servername servername, name, crdate
from sys.sysdatabases
where name = db_name()
if you have an issue running that, just do a simpler version:
select ##servername, db_name(), ##version
Select top 20 * From tblNotary Order By ID Desc
Related
I have an instance running SQL Server 2014 Express Edition (64-bit Build 19044). I have the same machine running a MySQL server (innodb_version: 5.7.33, protocol version: 10, version_compile_machine: x86_64, version_compile_os: Win64), and I need to write some information in this MySQL Server through a SQL Server script (I need to connect multiple servers and I would like to center everything in this SQL Server. This MySQL server I'm talking about is one of them).
I've found many tutorials teaching to use linked servers, like the following: https://gunnarpeipman.com/mssql-mysql-linked-server/
I've configured the ODBC connection as a System DSN using both MySQL ODBC 8.0 Unicode Driver and ANSI Driver;
I could connect to the MySQL server, and list the tables in this server through SSMS's object explorer. Unfortunately, I spent A LOT of time trying to query data from this server, since I always get errors pointing as if I don't have enough permission to see columns from this table:
When trying to [right click table > Script table as > Select to > clipboard]
[DWGLUO].[dw_vtiger]..[dleads] contains no columns that can be selected or the current user does not have permissions on that object.
When trying to query some data with OPENQUERY:
SELECT * FROM OPENQUERY(DWGLUO_ANSI,'SELECT idlead FROM DWGLUO_ANSI.dw_vtiger..dleads')
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "SELECT idlead FROM DWGLUO_ANSI.dw_vtiger..dleads" for execution against OLE DB provider "MSDASQL" for linked server "DWGLUO_ANSI".
I can see all tables, but i can't see any columns :(
Also, by running the query below, I managed to find the column names, so they're there somewhere:
EXEC ('SELECT TABLE_SCHEMA,
TABLE_NAME,
COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = ''dleads''') AT DWGLUO_ANSI ;
TABLE_SCHEMA
TABLE_NAME
COLUMN_NAME
dw_vtiger
dleads
idlead
dw_vtiger
dleads
nome
... (continues) ...
If someone could help me I would really appreciate it. Thank you all in advance.
This question is related to: Debezium How do I correctly register the SqlServer connector with Kafka Connect - connection refused
In Windows 10, I have Debezium running on an instance of Microsoft SQL Server that is outside of a Docker container. I am getting the following warning every 390 milliseconds:
No maximum LSN recorded in the database; please ensure that the SQL
Server Agent is running
[io.debezium.connector.sqlserver.SqlServerStreamingChangeEventSource]
I checked Debezium's code on Github and the only place that I can find this warning states in the code comments that this warning should only be thrown if the Agent is not running. I have confirmed that the SQL Server Agent is running.
Why is this warning showing up and how do I fix it?
Note:
My current solution appears to only work in a non-production environment - per Docker's documentation.
LSN is the "pieces" of information related about your SQL Server changes. If you don't have LSN, is possible that your CDC is not running or not configured properly. Debezium consumes LSNs to replicate so, your SQL Server need to generate this.
Some approaches:
Did you checked if your table are with CDC enabled? This will list your tables with CDC enabled:
SELECT s.name AS Schema_Name, tb.name AS Table_Name
, tb.object_id, tb.type, tb.type_desc, tb.is_tracked_by_cdc
FROM sys.tables tb
INNER JOIN sys.schemas s on s.schema_id = tb.schema_id
WHERE tb.is_tracked_by_cdc = 1
Your CDC database are enabled and runnig? (see here)
Check if enabled:
SELECT *
FROM sys.change_tracking_databases
WHERE database_id=DB_ID('MyDatabase')
And check if is running:
EXECUTE sys.sp_cdc_enable_db;
GO
Your CDC service are running on SQL Server? See in docs
EXEC sys.sp_cdc_start_job;
GO
On enabling table in CDC, I had some issues with rolename. For my case, configuring at null solved my problem (more details here)
EXEC sys.sp_cdc_enable_table
#source_schema=N'dbo',
#source_name=N'AD6010',
#capture_instance=N'ZZZZ_AD6010',
#role_name = NULL,
#filegroup_name=N'CDC_DATA',
#supports_net_changes=1
GO
Adding more to William's answer.
For the case SQL Server Agent is not running
You can enable it by following :
Control panel >
Administrative Tools >
Click "Services"
Look for SQL Server Agent
Right click and Start
Now you can fire cdc job queries in your mssql.
PS: you need to have login access to windows server.
Another possibility of this error (I just ran into this warning myself this morning trying to bring a new DB online) is the SQL login does not have the permissions needed. Debezium runs the following SQL. Check that the SQL login you are using has access to run this stored procedure and it returns the tables you have set up in CDC. If you get an error or zero rows returned, work with your DBA to get the appropriate permissions set up.
EXEC sys.sp_cdc_help_change_data_capture
Please consider the following situation
I have Prod instance of SQL server 2012
Also Archive instance of SQL server express 2012
Prod sees Archive as linked server and is able to write data with similar query from some .net code that creates a transaction and the transaction is committed at the end.
insert into <ArchiveServer>.<database>.<schema>.<table>
Select * from <ProductionServer>.<database>.<schema>.<table> Where <some conditions>
Now after the transaction finishes I am able to execute the following query
select count(1) from <ArchiveServer>.<database>.<schema>.<table>
and it returns correct number of records in the context of production server.
Same query
select count(1) from <database>.<schema>.<table>
in the context of Archive server returned 0 records.
What might be the problem? I am out of clues.
Thanks
ANY IDEA ?
I have Sql Server Enterprise 64 need to find:
The last time the SQL Server DB have been accessed (time)
Detailed information (the inventory) of all applications and/or users accessing the DB.
Explanation: I am doing an inventory of all my databases (around 120) which would help me decide whether to keep the DB and that will help me a decision about: If the DB should be kept or consolidate it with another one.
I have been working with thise Scripts below but they are limited
1 not working on 2000-05. I need more details like program name, statut, hostname, userinfo ...
2-Need last used info
May be both needed to be combined and refined.
Script 1
WITH last_query_by_db (dbid, Last_query)
AS (select dbid, max(last_execution_time) 'Last_query'
from sys.dm_exec_query_stats
cross apply
sys.dm_exec_sql_text(plan_handle)
group by
dbid
)
select d.name, Last_query
from
sys.databases d
left outer join
last_query_by_db q on q.dbid = d.database_id
where d.name not in ('master','msdb','model','tempdb')
order by 1
Script 2
SELECT HOSTNAME, PROGRAM_NAME, STATUS, SPID
FROM MASTER..SYSPROCESSES
WHERE DBID= DB_ID('TestDB')
AND SPID != ##SPID
You can enable Login Auditing in SQL Server Management Studio. After that, you can see the logs like this:
In Object Explorer, expand a server, expand Management, and then expand SQL Server Logs.
Right-click a log and click View SQL Server Log.
Source: MSDN
To check for the application name, use SELECT APP_NAME(). (Source)
Also, there is an Activity Monitor in SQL Server that can provide valuable information:
Implement an audit session (enterprise ed only) or xevents session (which version are you on?) or logon trigger.
Here's how to implement a logon trigger:
http://technet.microsoft.com/en-us/library/bb326598.aspx
I have to include one report in my application showing offline/online activity of few databases on SQL Server 2008.
Could you please suggest how can I collect teh same information from sql server?
SELECT DATABASEPROPERTYEX('YOURDATABASE', 'Status')
DatabaseStatus_DATABASEPROPERTYEX
GO
SELECT state_desc DatabaseStatus_sysDatabase
FROM sys.databases
WHERE name = 'YOURDATABASE'
GO
This will tell you the status of the database.
In order to find out when your database was taken OFFLINE, you can use the SQL that I posted before, or the easiest way is to check the Event Viewer and it will tell you when the Database was taken OFFLINE. I have just tested this on my local machine and SQL Server writes out an Information message to the Application log.
You can also use below query to check database status.
SELECT Name, state_desc FROM sys.databases