Dynamic stored procedure in different SQL servers? - asp.net

My client wants to change servers from the application, I mean enter new SQL servers name from application and search keywords in the SQL server database tables. I have Stored Producer which is working fine for one SQL server.
If client changes SQL server name in the application level then My connection string in the application will not work. Because database in the connection string that I used is available for one server.
How can I handle this situation? . Is there anyway sp that will be dynamic? P

Well in one server you could create a synonym that points at the other server. Assuming you have linked servers, on Server1:
CREATE SYNONYM dbo.ProcedureName FOR Server2_Linked.DatabaseName.dbo.ProcedureName;
Now when the app calls dbo.ProcedureName in Server1, unbeknownst to it, it is actually executing on Server2.
If this isn't what you're after I think you'll have to elaborate in your question a bit.

Related

How to "host" SQL Server when deploying an ASP.Net site on the web

I'm about to deploy an ASP.NET web application for testing in production. Essentially, this is just a table that is linked to a SQL Server table/view that is obviously dynamic when the data in the tables are updated.
I have a hosting plan with a site that I'll be pushing the files to, which includes a SQL Server database in the hosting plan. I also host a SQL Server instance on the network.
My question is, what is the standard way of dealing with SQL Server in this deployment? I think I have the options below, but as someone who has only ever developed applications offline, this is new to me, so please excuse my novice ignorance.
Have the application connect via IP address in the connection string to my SQL Server instance, as specifying the server name (SQLDEVSRV01 for example) won't be on the "network" when it's sitting in the site's FTP. Am I to assume my connection string will only work on the network, and once deployed to a website, will cease to function unless connecting via TCP/IP?
Host the server on the web in the same site host location. So upload the site files to my website host and setup the SQL server there. Would I be able to just specify the Server name (SQLDEVSRV01 for example) in the connection string there, as whilst it wouldn't work in development as it wouldn't be on the same network, it would then work once deployed on the web?
Embed a SQL Server instance within the app using localdB or something similar to hold the background data. If this is the case, can the data be accessed from the backend, either using SSMS or some other method?
Essentially, my aim here is to have the web app retrieve the data live from a view/table hosted in SQL server, where the backend data can be amended, manipulated and updated independently of the app, so the app can just pull the data when refreshed.
The standard way of doing this is to deploy your database to the hosting providers SQL Server instance and then connect your app to it using a connection string with their details. As it is normally a shared instance you do not have to normally worry about having the SQL instance machine patched etc.
Personally I would not be installing SQL Server myself unless I decided there was benefit to having an instance I wanted the control over nor would I be changing the structure or implementation of my application to suit a hosting providers setup.

Java Web application getting Cannot create PoolableConnectionFactory DB2 SQL Error: SQLCODE=-1776 for HADR configured on DB2

I have developed a web application where in i've configured two <Resource> with proper parameters in server.xml of Apache tomcat server, Using JNDI connection pool. Among two resource tags in server.xml, first tag is having details of primary server and another tag contains the details of standby server. My idea is if i dont get connection from primary for certain time, I'll switch the datasource to standby and run the query from servlet. But when I ran the code, It gave me the error Cannot create PoolableConnectionFactory (DB2 SQL Error: SQLCODE=-1776, SQLSTATE= , SQLERRMC=1, DRIVER=3.57.82)
I googled lot but cant find any concrete answer about this, but one thing was common in all i.e. HADR(Hisgh Availability Disaster Recovery) configuration of DB2 server.
Please help me out.
Generally speaking, you cannot connect to the standby database unless it assumes the primary role after the take-over.
The correct way of setting up a DB2 HADR cluster is to configure a virtual IP address in your cluster management software that gets assigned to the new primary database after the take-over; while the change remains completely transparent for client applications.
You'll need to talk to your DBAs to learn how to configure the application.
In a HADR configuration, each time the database flips from primary to standby and the standby to primary, the Server will send ClientReroute Exception to each client connected to DB2 server, So I've caught it programtically and and tried the transaction again and it succeeded.

can not connect to SQL database on amazon EC2 - microsoft project server database

I am using SQL managment studio 2008 running on an Amazon EC2 machine. I am unable to connect to the database in my asp.net application. The EC2 instance has been set to accept connections over the SQL port. I am also able to remote the machine as well as view websites hosted on the server. Listed below is part of the connection string relating to this instance. When the program is ran and this connection string is called, it returns tcp error 0 - no return response. it just times out.
<add name="ProjectServer" connectionString="Data Source=*IP ADDRESS HERE*,1433;Initial Catalog=*Catalog Name*;User ID=IP-0A6ED514\Administrator;"/>
I removed the ip and the catalog name for the example, but I am sure they are correct.
The only thing that I could think may cause an error, is the differences in names between the user id and the server name - the server name is ip-0A6ED514\sharepoint but the user name is ip-0A6ED514\administrator when I log into the sql server manager on the EC2 instance. A password is not used. Not sure if I would need to leave in a blank string for password - also not sure if the difference between server name and user id to log in makes a difference. Any help is appreciated. Thank you.
update - when this connection string is used with out the port, i get tcp provider error 40 - when the port is in there, i get error 0
edit- the sql server is using windows authentication - does this make a difference? Usually I always use SQL server authentication
edit 2- now running sql express at same location, would i need a \SQLEXPRESS tag? I feel like after looking around and what could be the error, it is that I am reaching the machine ok, but its not pointing me to the DB, any suggestions?

Multiple connections on a single .mdf database (ASP.net) SQL Server

I'm trying to place a .mdf database on a Computer A and access it simultaneously on Computer B but I'm having an error that says I cannot access the mdf file because it's being used by another process.
The setup is, the database is hosted on a Public folder in Computer A. I have Visual Studio running on both computers, and Computer B accesses the database on Computer A.
Computer A Connection path string:
C:\Users\Public\database.mdf
Computer B Connection path string:
\192.168.254.8\Public\database.mdf
Is there some sort of setting that I do not know of to enable multiple access on a db? Or this is not possible?
EDIT:
Let me rephrase my question, sorry.
There are two computers connected via a network, and I want to access one Visual Studio solution/project website. I wanted to do this as a demonstration, is it possible?
You should have an instance of SQL Server (even express) running on the host machine.
All requests from the clients should use the standard mechanisms for connecting to that server instance. In other words, they won't run their own copy of SQL Server, instead they will connect to the instance running on the host machine.
Simultaneous or direct access to Database files under any DBMS control either a very bad practice or simply impossible.
Use proper DBMS tools to access the data.
And yes - its possible to access Web site project for demo.
Install SQL Server on the host machine (the one that you want to keep your database on).
Then in Visual Studio, use the "Server Explorer" to locate the remote instance of the database. From there, you can utilize the remote instance of SQL Server in your connection string, thus allowing you to connect multiple computers to a single database.
Using two instances of SQL Server to connect to the single .mdf file is a very bad practice.
Instead of specifying the MDF file in your connection string (which, I believe, uses a form of User Instancing), you should use SQL Server Management Studio (SSMS) to attach the MDF. Then connect to SQL Server, rather than to the MDF.
You may need to move the MDF and LDF files to a place where the SQL Server identity can access them, rather than keeping them in your VS project.
Most projects keep scripts to create the DB in their VS project, but not the binary MDF itself.
When you deploy, the process is similar: use SSMS to attach the MDF on your server.
Yes, If 2 or More Computers are connected by networks like LAN You can access the Database Database1.mdf (say) from another SQL Server by entering its user name / Password /by Visual studio connection.
Disadvantages:
If more than 7~8 systems are accessing same Database same time System response slows down and Hangs up or may result error like connection pool exceeded or Device not responding..
In Big Companies they use Huge Multi-core & Multi-Processer based sever which will respond faster.
Overcome: while writing Applications Use Connection Open and Close Particularly while executing the SQL queries in other time it should be closed.
Best Programer uses Transaction instead of using normal methods. Transaction Makes Every User Access Database With valid and successful Execution of queries. These Queries (Transaction Queries) mainly executes on client machine and later updates the same over Main server when it got Time slot for it(synchronize).

How to get Web Application and DB Server High Availibility

I have a Web application made in ASP.NET and MS SQL 2005 as database
ASP.NET Web App is hosted on : http://192.168.0.90
and MS SQL Server DB on : 192.168.0.91
User use url : http://192.168.0.91 to access the server.
MY DR IP address for Web App http://192.168.0.150 and Database is : 192.168.0.151
Suppose my Web Server Fails. i need to Automatically divert user to my Web Application DR Server IP
same with DB Server.
without user knowing it ? how can i do it...
Waiting for your earliest revert.
Regards
Hasnain
preferred is the process should be automatic
For the web application use DNS instead like myapp.domain.com and assign two IPs (A records) to it. It will be working as round-robin load balancing and when one server will crash, it will direct you to the another one. This is the simplest yet quite effective method providing some extra availability, assuming you have session in external database or you are using clustered storage.
Also, when one of your webservers is not available, you can dynamically remove it's IP from the DNS, and this DNS A record should have 300 seconds TTL.

Resources