Checking database mirroring status in C# - c#

Our C# application needs to connect to SQL 2005 and 2008 databases and check what the current status of database mirroring is (eg. is it enabled, suspended, paused, disconnected etc). Are there properties where I can check this?
All our databases that are being mirrored have no witness and manual failover (synchronous mirroring).
Much appreciated if anyone can help out or point me to some documentation, google searches are not turning up much on this.

Current state is shown in sys.database_mirroring:
SELECT mirroring_state
FROM sys.database_mirroring
WHERE database_id = DB_ID('...');

The MSDN Article here describes all the System Stored procedures that will give you the information you need
You can also retrieve or update the
current status by running the
sp_dbmmonitorresults system stored
procedure.
One non-obvious difference between using the sp_dbmmonitorresults and using sys.database_mirroring table that's in Remus's answer is the permissions required
Rights needed for sys.database_mirroring
According to the MSDN article Remus referenced
To see the row for a database other
than master or tempdb, you must either
be the database owner or have at least
ALTER ANY DATABASE or VIEW ANY
DATABASE server-level permission or
CREATE DATABASE permission in the
master database. To see non-NULL
values on a mirror database, you must
be a member of the sysadmin fixed
server role
Rights needed for sp_dbmmonitorresults
According to the previous mentioned MSDN article on mirroring SP's
members of the sysadmin fixed server
role, and users who have been added to
the dbm_monitor fixed database role

Related

Read only queries Using ADO.NET

I want to limit the application to read only queries. In other words, I want the application to process only those queries which are not changing the state of the database. I am using ADO.NET. I do not want to create a new user against the database with read only permissions. Any suggestions are welcome.
Option 1: SQL Authentication
You can use connections as shown below:
Server ={serverName}; Initial Catalog = {DB_Name}; User Id={uid}; Password={pwd};
Use the uid which has only read access in database.
Option 2: Windows Authentication
If you want to use Integrated Security = True; (i.e. windows authentication) then you will have to grant readonly access to the windows user (under which the program runs).
Hope this helps.
You can create triggers to cancel any insert update or delete through a trigger at the database level. The trigger would end with a rollback to cancel the transaction. You would have to figure out who kicked off the trigger so other users can update the db.
I would not do it - I would take away any permission (except select) from the account being used for the application. I have created many, many triggers but I have never heard anyone using database triggers to enforce read only.

Can't store users in the default MVC application

I had some problems with using the authorization before so I got a brand new everything - new computer, new OS, fresh installation of VS, new app and DB in a new resource group on the Azure. The whole shabang.
I can confirm that I can log in to the Azure DB as the screenshots below show.
I can see the databases, tables, users etc.
The problem is that, although it works locally (using the default connection string provided automagically for me), it doesn't perform very well in the Azure (although I'm using the publish file from there). It said something about the file not being found and according to this answer, I needed to change the connection string.
After I've altered it, I get the following error. Please note that the firewall is open and that I can access the DB when I run the code of my applications. I feel that there's something that goes wrong when the authentication part is automatically configured. I'm out of ideas on how to trouble-shoot it, though.
[SqlException (0x80131904): Login failed for user 'Chamster'.
This session has been assigned a tracing ID of '09121235-87f3-4a92-a371-50bc475306ca'. Provide this tracing ID to customer support when you need assistance.]
The connection string I'm using is this.
Server=tcp:f8goq0bvq7.database.windows.net,1433;
Database=Squicker;
User ID=Chamster#f8goq0bvq7;
Password=Abc123();
Encrypt=True;
TrustServerCertificate=False;
Connection Timeout=10;
This issue's bothered me for a while and I'll be bounting it in two days. Any suggestion's warmly appreciated.
I believe I've managed to resolve this weird issue. It appears that the user I'm using, despite being admin with all bells and whistles isn't recognized as admin when used in the connection string and trying to create the tables (which is the case at the first registration).
My solution was to create two logins - one with db_owner role and one with db_datareader and db_datawriter. First, I've used the elevated user in my connection string and registered a single user. That created the tables in the database as shown below.
Then, while able to continue as admin, I realized that we should try the demoted user and tada!, it worked perfectly. Once the tables were there, the whole shabeling behaved as expected.
To be perfectly sure, I dropped the tables from the database and there it was - the same issues as before. When I changed to the elevated user, the tables were restored allowing me to get back to the demoted one.
I also tried dropping the tables, confirming the issues to re-appear and then creating the tables manually. That works too! So basically,the only gotcha that caused it all was the original admin who's not treated as admin.
It might have to do with the fact that my Azure account's getting a bit old, LiveID used there is ancient and that didn't have an updated version of DB in Azure (the pull-up to v12 was carried out the 18th of December, so it's possible that it also was a requirement to get it working). I'm too tired and lazy to check that out and I realize that I've no idea how to get an "old" type of account. Besides, the issue will decrease and gradually vanish because the old accounts get upgraded eventually.

Tally database synchronization with c# Application

I want to make an application to sync Tally Sales Order and Sales Invoice from tally to our SQL Database. Currently for testing purpose I am using Tally ERP 9 Educational Version.
I have created some sales orders in tally and need all order with their details from tally using tally ODBC Sql query
uptil as per my research, I am getting few sales order details like Voucher Number,Order Date,'Voucher Type'.. etc. from tally ODBC table CompanyVoucher. but few details came empty, although related data exist in tally order. like Reference , Party Name ... etc.
Also, I am unable to find Tally ODBC table to get few other sales order related data like item name, item number , item quantity, rate and order total, order no etc.
Can anybody suggest SQL Query or Tally ODBC Table from where i can find these order related data. Also I am not sure, if we can not access these details due to Educational Version, and any limitations on Educational Version on access of these details.
so please suggest me on this.
Synchronisation is the process of replicating data between two or more computers using Tally.ERP 9 in a Client – Server environment. Data is transferred from the client to the server and vice versa. Tally.ERP 9 offers control over the frequency of Synchronisation i.e., data can be replicated after each transaction or updated at specific intervals.
Configure Server for Synchronization
To configure the Server Company for Synchronization, follow the steps given below:
Go to Gateway of Tally > F12: Configure > Advanced Configuration
In the Advanced Configuration screen,
Under Client/Server Configuration section,
Set the option Tally is acting as to Server, to run Tally.ERP 9 as Sync Server
Specify the required port number (e.g. 9009) in the Port field....
Tab down to Tally Sync Configuration section:
Set the option Ignore Clients modified Voucher Type Masters to No, so that modifications made to Voucher Type Masters on the Client are updated on the Server
Set the option Enable Sync Logging to Yes, to generate a Log file which contains synchronized vouchers and is saved in the Tally folder.
Set the option Truncate previous log before Syncing should be set to Yes, to allow the previous log file to be overwritten by the current log file.
Go to end and press Enter to save the details.
For the above changes to take effect, Tally.ERP 9 will prompt you to restart the application as shown:
Press Enter or select Yes to restart Tally.ERP 9 on the Server computer.
Tally.ERP 9 will restart and in the Information Panel you can see that it is configured as the Sync Server as shown below.
Detailed reference here.
If the datas are present and you cannot access the sync then there
must be restriction in your version

Inserting different data simultaneously from different clients

I created a windows forms application in C #, and a database MS SQL server 2008 Express, and I use LINQ-to-SQL query to insert and edit data.
The database is housed on a server with Windows Server 2008 R2 (standard edition). Right now I have the application running on five different computers, and users are authenticated through active directory.
One complaint reported to me was that sometimes when different data is entered and submitted, the same data do not appear in the listing that contains the application. I use try catch block to send the errors but errors do not appear in the application; but the data simply disappear.
The id of the table records is an integer auto-increment. As I have to tell them the registration number that was entered I use the following piece of code:
try{
ConectionDataContext db = new ConectionDataContext();
Table_Registers tr = new Table_Registers();
tr.Name=textbox1.text;
tr.sector=textbox2.text;
db.Table_Registers.InsertOnSubmit(tr);
db.SubmitChanges();
int numberRegister=tr.NumberRegister;
MessageBox.Show(tr.ToString());
}
catch{Exception e}
I wonder if I'm doing something wrong or if you know of any article on the web that speaks how to insert data from different clients in MSSQL Server databases, please let me know.
Thanks.
That's what a database server DOES: "insert data simultaneously from different clients".
One thing you can do is to consider "transactions":
http://www.sqlteam.com/article/introduction-to-transactions
Another thing you can (and should!) do is to insure as much work as possible is done on the server, by using "stored procedures":
http://www.sql-server-performance.com/2003/stored-procedures-basics/
You should also check the SQL Server error logs, especially for potential deadlocks. You can see these in your SSMS GUI, or in the "logs" directory under your SQL Server installation.
But the FIRST thing you need to do is to determine exactly what's going on. Since you've only got MSSQL Express (which is not a good choice for production use!), perhaps the easiest approach is to create a "log" table: insert an entry in your "log" every time you insert a row in the real table, and see if stuff is "missing" (i.e. you have more entires in the log table than the data table).

updating changes from one database to another database in the same server

I have a copy of client database say 'DBCopy' which already contains modified data. The copy of the client database (DBCopy) is attached to the SQL Server where the Central Database (DBCentral) exists. Then I want to update whatever
changes already present in DBCopy to DBCentral. Both DBCopy and DBCentral have same schema. How can i do it programatically using C#.NET maybe with a button click. Can you give me an example code as how to do it?. I am using SQL Server 2005 Standard Edition and VS 2008 SP1.
In the actual scenario there are about 7 client database all with same schema as the central database. I am bringing copy of each client database and attach it to Central Server where the central database resides and try to update changes present in each copy of the client database to central database one by one programatically using C# .NET . The clients and the central server are physically seperate machines present in different places. They are not interconnected.
I need to only update and insert new data. I am not bothered about deletion of data.
Thanks and regards
Pavan
Go check out Sync Framework. Otherwise, go create some SSIS packages and run them.
What you are describing sounds an awful lot like Database Mirroring.
If this is a one-time or infrequent sync, then I'd use a third-party tool such as Red-Gate's SQL Data Compare. If this is meant as an ongoing sync, then I'd recommend replication or the Synchronization Framework.
i think this is wht u want:-----
USE DB1
UPDATE DB1.dbo.MyTable
SET
Field1 = d2.Field1,
Field2 = d2.Field2,
Field3 = d2.Field3
FROM DB2.dbo.MyTable d2
WHERE d2.MyKey = MyTable.MyKey

Categories

Resources