473,657 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open SQL connection using T-SQL

2 New Member
I would like to connect to a remote sql server using a stored procedure. I had planned on using OPENQUERY( linked_server ,'query' ) to pull data from the remote server but this command does not accept variables for its arguments. Is there another way to open a connection using Transact-SQL?

Thanks for your help!
Nov 5 '09 #1
2 3245
ck9663
2,878 Recognized Expert Specialist
Will this work:

Expand|Select|Wrap|Line Numbers
  1.  
  2. exec ('select * from linked_server.' + @dbname + '.dbo.' + @tablename + ' where blah blah order by blah blah'
  3.  
  4.  
That's just a pseudo-code...

Happy Coding!!!


--- CK
Nov 5 '09 #2
muddler
2 New Member
I guess I just needed to treat it like any other query but include the linked server name in the string.

I'm still pretty wet behind the ears. Thanks so much for your help ck9663. This was my first visit to this sight. I appreciate you taking the time to reply.

- Muddler
Nov 6 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
455
by: Kevin Vogt | last post by:
When initially loaded, my web application (below) takes ~120000 milliseconds to open its connection. But repeated executions take 0 milliseconds each. But when I wait for approx. 5 minutes and try again, it takes another 120000 milliseconds for Open(). This behavior gets really irritating with the real web application that I'm working on. But the thing I don't understand is, when I make a console app that does the same sort of thing, the...
6
7541
by: Mojtaba Faridzad | last post by:
Hi, I am newbie in C# and I am trying to design my first database program and I am trying to find the best solution. The database is MySQL. how do you open your connection in a big application? as I know, I should open a connection, set the dataset and close the connection. I should open the connection in "try" block and close the connection in "finally" block. is that right? I can write a service to pass the query and retreive the...
4
2467
by: Macca | last post by:
Hi, I have an windows forms application that accesses a SQL database I have a few questions as to connecting to the database. This application will run 24 hours a day. It is a monitoring application and will store events that happen in the database (These events happen randomly without pattern, between 10-50 a day) . There are a number of situations where the database is accessed.
4
3970
by: mescano | last post by:
I am currently implementing a singleton pattern for accessing a database. Is it advisable to close the connection to the database at all -- thus leaving it open or should it be closed. If closed, when should I it close it -- after the execution of the each command to the database? If leaving open, what impacts does it have. Imagining that it is one connection to the database. Thanks, mescano
29
7040
by: Bryce K. Nielsen | last post by:
Suddenly this week, I've started getting this error message: System.Data.SqlClient.SqlConnection(GetOpenConnection)ExecuteNonQuery requires an open and available Connection. The connection's current state is connecting. I'm very puzzled since I'm not calling "ExecuteNonQuery" and I am calling "Open", which I've always assumed was Synchronous, i.e. would not return until either A) the connection was open or B) there was an error. Here...
14
4604
by: martin1 | last post by:
All, I want to check wether db connection/open or not, if not it will post db connection error to user in message box The code is like: Dim objConnection As New SqlConnection _ ("Server=server1; database=db1;user id=user1;password=whatever") Dim objDataAdapter As New SqlDataAdapter() Dim objDataSet
8
14553
by: Imran Aziz | last post by:
Hello All, Like in C++ I tried to use constructor to open a database connection and distructor to close the database connection, it now turns out that one cannot create distrutors in C# classes. Here is my code public class DBLayer {
7
13551
by: fniles | last post by:
I am using VB.Net 2003 and MS Access (connecting using OleDBConnection). I read using DataAdapter and DataSet, not DataReader. When many people try to access the database at the same time, I get the error "ExecuteReader requires an open and available Connection. The connection's current state is Open, Executing." I do not use ExecuteReader, why the error says ExecuteReader. What does it mean ? When I get this error, is there a way for me...
5
3384
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open left, I always see that there are 2 connections open and in "ESTABLISHED" state. Here is the piece of code that I'm using, please tell where I'm doing it wrong. Since this class is being used at many placed in my actual web based application that...
6
4724
by: =?Utf-8?B?RyBIdXN0aXM=?= | last post by:
I am creating a new MS Access DB in code, which works fine. I then try to open it & set a password. I keep getting an error that the DB is already open by my machine's Admin account. In reality it is not actually open. Here is a look at my code for creating & then setting the Password. Dim ADOXcat As New ADOX.Catalog sCreateString = "Provider=" & Provider & ";Data Source=" & DatabaseFullPath Try ADOXcat.Create(sCreateString)
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.