Thursday, March 22, 2012
Connecting to SBS SQL via Remote VPN (VB Application)
Dont really know if this is the place to ask but here goes...
I have written a VB application that talks to various SQL2000 Tables. But i
need to expand the VB App to work on a laptop thats remotely connected by VP
N.
Even though the laptop is connected via VPN and can use server applications
it cannot see the SQL server? and produces (can find it errors).
Is there anything i need to do to the sql server to allow outside
connections or to the ISA firewall etc etc.
Any help will be appreciated.
Regards
TIMIf you know that your VPN connection is working correctly, then next try
connecting to the database server using it's IP and port as the data source:
http://www.carlprothman.net/Default...derForSQLServer
If that doesn't work, then speak with your DBA and/or network admin. Perhaps
the following is relevent to your situation:
How To Use ADO to Connect to a SQL Server That Is Behind a Firewall
http://support.microsoft.com/defaul...b;en-us;Q269882
INF: TCP Ports Needed for Communication to SQL Server Through a Firewall
http://support.microsoft.com/defaul...b;EN-US;q287932
"TIM" <TIM@.discussions.microsoft.com> wrote in message
news:C10D5F9D-F628-4B57-9EF3-707C9E621DA9@.microsoft.com...
> Hi,
> Dont really know if this is the place to ask but here goes...
> I have written a VB application that talks to various SQL2000 Tables. But
> i
> need to expand the VB App to work on a laptop thats remotely connected by
> VPN.
> Even though the laptop is connected via VPN and can use server
> applications
> it cannot see the SQL server? and produces (can find it errors).
> Is there anything i need to do to the sql server to allow outside
> connections or to the ISA firewall etc etc.
> Any help will be appreciated.
> Regards
> TIMsqlsql
Sunday, March 11, 2012
Connecting to Interbase from MSDE
I'm new to MSDE and need some help. I have a stored proc that used to sit in Interbase and when executed it would populate some tables. I now have to have these tables external to the interbase database and have chosen (for the initial phase at least) to use MSDE. I have created a table (the first of many) and now working on the procedure.
My question is how do I connect to the interbase database. I have an ODBC setup (which is used in a VB application on the client) and I assume I need to use that, but I'm not sure how to implement the connect command in the stored proc. Any ideas?
Cheers in advance,
Kevin.Just to add that I need to use a cursor within the procedure that reads the data from the Interbase database then based on the values writes to the MSDE table. Don't know if this makes it any clearer :-)
Cheers,
Kevin.
connecting to AS400
Hi,
I am trying to transfer information from the AS400 to SQL Server tables but I am having problems trying to connect and get information from the AS400. In the data source I select the iseries connection and type in the ip address, username, and password. When I click the test connection button, it connects but under the initial catalog all I get is the computer name. If anyone has any solutions to my problem that would be great
Thnaks
Brian
I have had success connecting to the AS/400 only with an ADO Data Reader (could not use an OLE DB Source) using the IBMDA400 Provider (connections string included below). You must also explicitly specify libraries in your select statements, and not rely on library list.
Sample connection string:
Data Source=server;User ID=uid;Provider=IBMDA400.DataSource.1;Persist Security Info=False;Connect Timeout=300;Catalog Library List=library1, library2;
Thursday, March 8, 2012
Connecting to another database
database on the same server. Is it possible that when the users open these
views (through the Web pages) they are connected to the database2 under
another login (not the login which is used to connect to the current
database)?
Thanks.
Hi Vik,
What is the purpose of this? If your web application connects to database2,
the view is not going to be the present there and you need to use
database1..view to connect to the view.
And if you want the web app to connect to database 2 under another login,
that has to be defined in your application's connection string.
Thanks
Yogish
|||No, if you SELECT from a view then you use the same connection. Of course, the application
programmer might have written the application so that it opens another connection using another
login...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Vik" <viktorum@.==hotmail.com==> wrote in message news:OKVKhUqEFHA.3984@.TK2MSFTNGP14.phx.gbl...
> In a SQL Server database, there are views based on the tables from another database on the same
> server. Is it possible that when the users open these views (through the Web pages) they are
> connected to the database2 under another login (not the login which is used to connect to the
> current database)?
> Thanks.
>
|||In the db1, there are:
Table1,
View1 based on the db2 (should be read only),
View2 based on the Table1 and View2. The Web page is based on the View2,
that is the page connects to both databases using one connction string.
The users of the Web page log in with their own userid, and these logins
exist in the db1 as we need to record (using the triggers) which user
entered/modified data.
The users of the db1 need read-only access to the db2 (through the View1)
and could use one common login to the db2 as the db2 does not need to know
who connected to it with read-only access.
So, I wanted to use one datareader login in the db2 instead of creating the
logins in the db2 for each user of the db1. I supposed there may be a way to
specify a connection to the db2 in the View1 itself.
Thank you.
Vik
"Yogish" <yogishkamathg@.icqmail.com> wrote in message
news:68ABC6F8-FC87-44C6-BD04-B6811725938B@.microsoft.com...
> Hi Vik,
> What is the purpose of this? If your web application connects to
> database2,
> the view is not going to be the present there and you need to use
> database1..view to connect to the view.
> And if you want the web app to connect to database 2 under another login,
> that has to be defined in your application's connection string.
> --
> Thanks
> Yogish
>
|||You should read about ownership chains and also about "Cross DB Ownership Chaining". If you don't
want the users to exists in the db where the table resides, you need to turn on cross database
ownership chaining. But you also need to make certain that you have proper owner for the tables and
views (so you don't get a broken ownership chain).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Vik" <viktorum@.==hotmail.com==> wrote in message news:eAu2TTrEFHA.392@.TK2MSFTNGP14.phx.gbl...
> In the db1, there are:
> Table1,
> View1 based on the db2 (should be read only),
> View2 based on the Table1 and View2. The Web page is based on the View2, that is the page connects
> to both databases using one connction string.
> The users of the Web page log in with their own userid, and these logins exist in the db1 as we
> need to record (using the triggers) which user entered/modified data.
> The users of the db1 need read-only access to the db2 (through the View1) and could use one common
> login to the db2 as the db2 does not need to know who connected to it with read-only access.
> So, I wanted to use one datareader login in the db2 instead of creating the logins in the db2 for
> each user of the db1. I supposed there may be a way to specify a connection to the db2 in the
> View1 itself.
> Thank you.
> Vik
>
> "Yogish" <yogishkamathg@.icqmail.com> wrote in message
> news:68ABC6F8-FC87-44C6-BD04-B6811725938B@.microsoft.com...
>
Connecting to another database
database on the same server. Is it possible that when the users open these
views (through the Web pages) they are connected to the database2 under
another login (not the login which is used to connect to the current
database)?
Thanks.Hi Vik,
What is the purpose of this? If your web application connects to database2,
the view is not going to be the present there and you need to use
database1..view to connect to the view.
And if you want the web app to connect to database 2 under another login,
that has to be defined in your application's connection string.
Thanks
Yogish|||No, if you SELECT from a view then you use the same connection. Of course, t
he application
programmer might have written the application so that it opens another conne
ction using another
login...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Vik" <viktorum@.==hotmail.com==> wrote in message news:OKVKhUqEFHA.3984@.TK2MSFTNGP14.phx.gbl
..
> In a SQL Server database, there are views based on the tables from another
database on the same
> server. Is it possible that when the users open these views (through the W
eb pages) they are
> connected to the database2 under another login (not the login which is us
ed to connect to the
> current database)?
> Thanks.
>|||In the db1, there are:
Table1,
View1 based on the DB2 (should be read only),
View2 based on the Table1 and View2. The Web page is based on the View2,
that is the page connects to both databases using one connction string.
The users of the Web page log in with their own userid, and these logins
exist in the db1 as we need to record (using the triggers) which user
entered/modified data.
The users of the db1 need read-only access to the DB2 (through the View1)
and could use one common login to the DB2 as the DB2 does not need to know
who connected to it with read-only access.
So, I wanted to use one datareader login in the DB2 instead of creating the
logins in the DB2 for each user of the db1. I supposed there may be a way to
specify a connection to the DB2 in the View1 itself.
Thank you.
Vik
"Yogish" <yogishkamathg@.icqmail.com> wrote in message
news:68ABC6F8-FC87-44C6-BD04-B6811725938B@.microsoft.com...
> Hi Vik,
> What is the purpose of this? If your web application connects to
> database2,
> the view is not going to be the present there and you need to use
> database1..view to connect to the view.
> And if you want the web app to connect to database 2 under another login,
> that has to be defined in your application's connection string.
> --
> Thanks
> Yogish
>|||You should read about ownership chains and also about "Cross DB Ownership Ch
aining". If you don't
want the users to exists in the db where the table resides, you need to turn
on cross database
ownership chaining. But you also need to make certain that you have proper o
wner for the tables and
views (so you don't get a broken ownership chain).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Vik" <viktorum@.==hotmail.com==> wrote in message news:eAu2TTrEFHA.392@.TK2MSFTNGP14.phx.gbl.
.
> In the db1, there are:
> Table1,
> View1 based on the DB2 (should be read only),
> View2 based on the Table1 and View2. The Web page is based on the View2, t
hat is the page connects
> to both databases using one connction string.
> The users of the Web page log in with their own userid, and these logins e
xist in the db1 as we
> need to record (using the triggers) which user entered/modified data.
> The users of the db1 need read-only access to the DB2 (through the View1)
and could use one common
> login to the DB2 as the DB2 does not need to know who connected to it with
read-only access.
> So, I wanted to use one datareader login in the DB2 instead of creating th
e logins in the DB2 for
> each user of the db1. I supposed there may be a way to specify a connectio
n to the DB2 in the
> View1 itself.
> Thank you.
> Vik
>
> "Yogish" <yogishkamathg@.icqmail.com> wrote in message
> news:68ABC6F8-FC87-44C6-BD04-B6811725938B@.microsoft.com...
>
Connecting to another database
database on the same server. Is it possible that when the users open these
views (through the Web pages) they are connected to the database2 under
another login (not the login which is used to connect to the current
database)?
Thanks.No, if you SELECT from a view then you use the same connection. Of course, the application
programmer might have written the application so that it opens another connection using another
login...
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Vik" <viktorum@.==hotmail.com==> wrote in message news:OKVKhUqEFHA.3984@.TK2MSFTNGP14.phx.gbl...
> In a SQL Server database, there are views based on the tables from another database on the same
> server. Is it possible that when the users open these views (through the Web pages) they are
> connected to the database2 under another login (not the login which is used to connect to the
> current database)?
> Thanks.
>|||Hi Vik,
What is the purpose of this? If your web application connects to database2,
the view is not going to be the present there and you need to use
database1..view to connect to the view.
And if you want the web app to connect to database 2 under another login,
that has to be defined in your application's connection string.
--
Thanks
Yogish|||In the db1, there are:
Table1,
View1 based on the db2 (should be read only),
View2 based on the Table1 and View2. The Web page is based on the View2,
that is the page connects to both databases using one connction string.
The users of the Web page log in with their own userid, and these logins
exist in the db1 as we need to record (using the triggers) which user
entered/modified data.
The users of the db1 need read-only access to the db2 (through the View1)
and could use one common login to the db2 as the db2 does not need to know
who connected to it with read-only access.
So, I wanted to use one datareader login in the db2 instead of creating the
logins in the db2 for each user of the db1. I supposed there may be a way to
specify a connection to the db2 in the View1 itself.
Thank you.
Vik
"Yogish" <yogishkamathg@.icqmail.com> wrote in message
news:68ABC6F8-FC87-44C6-BD04-B6811725938B@.microsoft.com...
> Hi Vik,
> What is the purpose of this? If your web application connects to
> database2,
> the view is not going to be the present there and you need to use
> database1..view to connect to the view.
> And if you want the web app to connect to database 2 under another login,
> that has to be defined in your application's connection string.
> --
> Thanks
> Yogish
>|||You should read about ownership chains and also about "Cross DB Ownership Chaining". If you don't
want the users to exists in the db where the table resides, you need to turn on cross database
ownership chaining. But you also need to make certain that you have proper owner for the tables and
views (so you don't get a broken ownership chain).
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Vik" <viktorum@.==hotmail.com==> wrote in message news:eAu2TTrEFHA.392@.TK2MSFTNGP14.phx.gbl...
> In the db1, there are:
> Table1,
> View1 based on the db2 (should be read only),
> View2 based on the Table1 and View2. The Web page is based on the View2, that is the page connects
> to both databases using one connction string.
> The users of the Web page log in with their own userid, and these logins exist in the db1 as we
> need to record (using the triggers) which user entered/modified data.
> The users of the db1 need read-only access to the db2 (through the View1) and could use one common
> login to the db2 as the db2 does not need to know who connected to it with read-only access.
> So, I wanted to use one datareader login in the db2 instead of creating the logins in the db2 for
> each user of the db1. I supposed there may be a way to specify a connection to the db2 in the
> View1 itself.
> Thank you.
> Vik
>
> "Yogish" <yogishkamathg@.icqmail.com> wrote in message
> news:68ABC6F8-FC87-44C6-BD04-B6811725938B@.microsoft.com...
>> Hi Vik,
>> What is the purpose of this? If your web application connects to database2,
>> the view is not going to be the present there and you need to use
>> database1..view to connect to the view.
>> And if you want the web app to connect to database 2 under another login,
>> that has to be defined in your application's connection string.
>> --
>> Thanks
>> Yogish
>
Saturday, February 25, 2012
Connecting tables from a different database to an application
which must refer to a table in a SQLServer 2000 database other than the main
database. When I connect, I get the data but the recordset is not updatable.
I can create a view in the main SQLServer database that makes the connection
and can be updated, but when I open that view in Access, it's still not
updatable.
Is there some simple way to update the data?
Hi,
http://support.microsoft.com/kb/328828
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
"TLD" <TLD@.discussions.microsoft.com> wrote in message
news:D6D862E7-D3AB-48EA-92D2-2479620DC822@.microsoft.com...
>I have an application using an Access 2003 project connecting through ADO
> which must refer to a table in a SQLServer 2000 database other than the
> main
> database. When I connect, I get the data but the recordset is not
> updatable.
> I can create a view in the main SQLServer database that makes the
> connection
> and can be updated, but when I open that view in Access, it's still not
> updatable.
> Is there some simple way to update the data?
>
|||Thanks for your help, but I don't see the answer to my problem in the article
referenced.
"Jens K. Suessmeyer" wrote:
> Hi,
> http://support.microsoft.com/kb/328828
>
> HTH, Jens K. Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "TLD" <TLD@.discussions.microsoft.com> wrote in message
> news:D6D862E7-D3AB-48EA-92D2-2479620DC822@.microsoft.com...
>
|||The problem turned out to be that the "uneditiable" fields were char rather
than varchar. When the user put a cursor into the field, he wasn't able to
insert letters. Changing the configuration of the underlying table has
resolved the problem.
Thanks for your help.
"Jens K. Suessmeyer" wrote:
> Hi,
> http://support.microsoft.com/kb/328828
>
> HTH, Jens K. Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "TLD" <TLD@.discussions.microsoft.com> wrote in message
> news:D6D862E7-D3AB-48EA-92D2-2479620DC822@.microsoft.com...
>
Connecting Tables
I am beggining in SQL and the .NET framework and have been running into some problems trying to design a relational database. I am completely new to it so I bought a book that was recommended in this Forum called "Handbook of Relational Database Design" and it has been pretty usefull so far. RIght now I am trying to make the Logical Data Model before I make the Relational Data Model.
The problem that I am having right now is creating a table that is a derivation from another table. For example, in the book they have a table called Property, and then two other tables called MountainProperty and BeachProperty. MountainProperty and BeachProperty are a type (relationship here) of a property. So basically Property will hold some data in a table, and then MountainProperty and BeachProperty will extend that property to contain more specific data. This is very similar to what I want to do. However I am having a problem understanding how an instance (or row) in Property, will have a link (foreign key) to a piece of data that is in Mountain or BeachProperty. I understand the foreign key in Mountain and BeachProperty and how they will link back to their "parent". But how will Property know its children, where is the link for that, how can one make a link to that. You could make a column with a foreign key, but which table would it point to, can one column point to mulitple tables? That doesn't make very much sense to me.
Basically what I am trying to say is that a row in the Property table can be multiple types, and these types will store more additional data about that row. How can I link to that data from that row in the table Property.
The only way that I can think of to link to that table is by making another column called PropertyType where MountainProperty equal 1 and BeachProperty equals 2. So I would perfrom a query in my application on the row like "Select PropertyType from Property" which would give me back 1 or 2. Based upon that I would then know which table to search for in the database and would then perfrom another query on the specific table, either MountainProperty or BeachProperty.
I am terribly sorry if this is confusing or if it is so appartently easy for you, but this is the first time that I have ever tried to make a relational database and I am really struggling on seeing how to organize these tables properly. Thank yor for your time.
Jeremy
(But how will Property know its children, where is the link for that, how can one make a link to that. You could make a column with a foreign key, but which table would it point to, can one column point to mulitple tables? That doesn't make very much sense to me.
Basically what I am trying to say is that a row in the Property table can be multiple types, and these types will store more additional data about that row.)
Hi,
I tried the answer your question but could not find it, tables in the relational model since I have been doing data back in 1998 are entities, the only property per ANSI SQL definition in the DDL(data definition language) is IDENTITY. So you design tables by files and association and relationship is determined by upper and lower bound cardinality.
There is a better book called Data Modeling by G. Lawrence Sanders and there are existing free data models you can clone to use. You questions about the relationship is through DRI(declarative referential integrity) which means if a references b b must exist so primary key a becomes foreign key b so you can use a to delete b Cascade Delete and a to update b Cascade Update and a to set b to default Cascade Set Default and Null Cascade Set Null. If the above is confusing it is because it was created with a 26 pages long algebra and took many years to implement. If you have many references then you need a DRI trigger because the built in version will not go beyond three. Hope this helps.
http://www.databaseanswers.org/data_models/index.htm
http://www.databaseanswers.com/modelling_books.htm
|||Truthfully, I didn't really understand anything you said, maybe just a little when you talked about the Cascade Delete stuff. But it was all inference. Anyone else have any suggestions for my predicament?|||
EDIT
You did not understand it because I did not say what you expect, what I am saying the only properties relating to tables is IDENTITY so all you have been trying to create is not working because it is not correct. And spend time with the links posted because that material is by Data Modeling experts.
|||OK, as far as I understood you are talking about realtional inheritance. This is not automatically possible in SQL Server, you will (according to your sample) have to implement that on your own. Let me explain how I see your problem: You have two tables, one tables with the common values for properties (the parent table) and the specific table according to the type mentioned in the property table. If you query the table property you want SQL Server to pick either the child values from the one or the other child table, depending on the property type in the parent table. Unfortunately and as aletady mentioned, this is not implemented in SQL Server. Although a FK / PK raltionships can be implemented you will have to you aour own retrieval logic to get the data back. You can implement this usingeither client logic or server logic (like stored procedures). Hope that hits your question, if not do not hesitate coming back.
Jens K. Suessmeyer
http://www.sqlserver2005.de
connecting SQLExpress & Visual C# 2005
Hi
I have started to create a databse using SQL Server Management Studio Express, just a few tables, one with data. I now want to creat a some windows forms to populate the tables. However when I try to use the Add New Data Source wizard, I get an error when I try to create the connection string, but I have managed to connect to a copy of AdventureWorks located in the same parent directory.
Error is :
Unable to open the physical file "...". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)".
An attemp to attach an auto-named database for file ... failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
As I can connect to AdventureWorks, I presume Windows thinks the file is open, but I have no idea why, how to check, or how to close it.
TIA
Graham
Now Sorted not quite sure what I did, but I have downloaded some updates today, and I did start by looking at the data in Adveture works before I opened my projectSunday, February 19, 2012
Connecting Execute SQL Task with Firebird Connection Manager
Hi,
I'm using Integration Service between Firebird and MS SQL 2005. I can able to move data from Firebird db tables to MS SQL db tables using DataReader source (Firebird Connection Manager) and SQL Server Destination (SQL Server Connection Manager) component.
Now I want to execute parametrized SQL statement to fetch data from Firebird DB using Execute SQL Task Component. In this process while trying to set Connection property to this component I can able to view only MS SQL Connection Manager and it is not listing Firebird Connection Manager.
FYI. I'm using Firebird .Net Provieder 2.0.1
Thanks in advance.
Suku
More clarification on my query
Here, the mentioned Firebird Connection Manager is a custom created connection manager and we created using Firebird .Net Provider 2.0.1
I tried with Lookup component too, it shows only the destination connection Manager (MS SQL) but not the Source one (Firebird Custom Connection Manager).
Suku
|||Could you try to set the connection type to Ado .NET in the Execute SQL Task UI?
Lookup can only use OLE DB connections not Ado .NET.
Thanks.
|||Hi,
Were you able to resolve this issue? I also have a custom connection manager that I am trying to use from Execute SQL Task. Unfortunatelly I don't see my connection object in Execute SQL Task Editor, though it gets added as a new connection successfully. My custom connection manager is basically a very simplified version of the Microsoft's SqlConnectionManager Sample. I am trying to make a custom connection manager which will hide the login info.
Thanks!
Connecting Execute SQL Task with Custom Connection Manager
Hi,
I'm using Integration Service between Firebird and MS SQL 2005. I can able to move data from Firebird db tables to MS SQL db tables using DataReader source (Firebird Connection Manager) and SQL Server Destination (SQL Server Connection Manager) component.
Now I want to execute parametrized SQL statement to fetch data from Firebird DB using Execute SQL Task Component. In this process while trying to set Connection property to this component I can able to view only MS SQL Connection Manager and it is not listing Firebird Connection Manager.
FYI. I'm using Firebird .Net Provieder 2.0.1
Thanks in advance.
Suku
More clarification on my query
Here, the mentioned Firebird Connection Manager is a custom created connection manager and we created using Firebird .Net Provider 2.0.1
I tried with Lookup component too, it shows only the destination connection Manager (MS SQL) but not the Source one (Firebird Custom Connection Manager).
Suku
|||Could you try to set the connection type to Ado .NET in the Execute SQL Task UI?
Lookup can only use OLE DB connections not Ado .NET.
Thanks.
|||Hi,
Were you able to resolve this issue? I also have a custom connection manager that I am trying to use from Execute SQL Task. Unfortunatelly I don't see my connection object in Execute SQL Task Editor, though it gets added as a new connection successfully. My custom connection manager is basically a very simplified version of the Microsoft's SqlConnectionManager Sample. I am trying to make a custom connection manager which will hide the login info.
Thanks!
Friday, February 17, 2012
Connecting and Getting data from 8 tables in one sql statement
Hi everybody,
I like to get data from 8 tables to be loaded in a dropdownlist or combobox control. Desired Result is need to be filtered by Region, Company, ProjectOffice, Country, and Location and still get all rows from 3 tables after applying filters. How can this be done in one single sql statement?
I have 3 separate sql statements which needed to be only one.
Select C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region'
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID Order By E.ProjectOfficeID
Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country'
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID
Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
W.LocationID, W.[Name] As 'Location'
From ProjectOfficeLocation L Left Join ProjectOffice P On L.ProjectOfficeID = P.ProjectOfficeID
Left Join Location W On L.LocationID = W.LocationID
Left Join Region R On P.RegionID = R.RegionID
Table structures (some columns)
Region table
RegionID Name
ProjectOffice table
ProjectOfficeID Name RegionID
Location Table
LocationID Name
Country table
CountryID Name
Company table
CompanyID Name
ProjectCompany table (All rows)
ID ProjectOfficeID CompanyID
ProjectOfficeCountry table (All rows)
ID ProjectOfficeID CountryID
ProjectOfficeLocation table (All rows)
ID ProjectOfficeID LocationID
maybe something like this ?Select 'A' as [type], C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region'
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID Order By E.ProjectOfficeID
UNION ALL
Select 'B' as [type], P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country'
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID
UNION ALL
Select 'C' as [type], P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
W.LocationID, W.[Name] As 'Location'
From ProjectOfficeLocation L Left Join ProjectOffice P On L.ProjectOfficeID = P.ProjectOfficeID
Left Join Location W On L.LocationID = W.LocationID
Left Join Region R On P.RegionID = R.RegionID
Thanks carlop for replying,
If I did that then I could not differentiate between CompanyID and ProjectID or Company From Project Office or Location From Region, there should be a better way to do this...
Thanks.
|||I really don’t understand why you need in single SQL Statement. Are you trying to fetch those result in single batch (single hit to server).
If you don’t use the union all then you have to use the JOIN. It may lead your (desired) result set to duplicates (for region & country) and it is not helpful on Combobox binding.
|||ManiD,
Trying to get say data for Company, filtered by Region,Country, ProjectOffice, Company and Location, then data will be used to fill the combobox or dropdownlist control.
|||are you like to hit the db server once to get those data.
or
you need to have all the data in columns..?
|||ManiD,
Well, that is ideal to get all columns I needed and without duplicates. I have used several sql statements to achive same result, I wonder if it can be done using one single sql statement.
|||While I agree with the other posters that this is not a very good idea, you could probably use union to put all of the data in a single result:
Select C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region', 'PURPOSE1' as purpose
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID
UNION ALL
Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country', 'PURPOSE2' as purpose
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID
Note that you would also need to genericize the other names, like the id, the name, etc. I almost feel wrong in suggesting this, because it seems so much cleaner to make N result sets and get the data one set at a time (much cleaner and certainly eaiser to implement.)
|||Thanks for the reply Louis.
It seems there is no exact way getting all data needed in just one sql statement. I would stick to using multiple sql statements in getting the results.
Thanks.
I think the issue in this thread is closed.
Connecting and Getting data from 8 tables in one sql statement
Hi everybody,
I like to get data from 8 tables to be loaded in a dropdownlist or combobox control. Desired Result is need to be filtered by Region, Company, ProjectOffice, Country, and Location and still get all rows from 3 tables after applying filters. How can this be done in one single sql statement?
I have 3 separate sql statements which needed to be only one.
Select C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region'
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID Order By E.ProjectOfficeID
Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country'
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID
Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
W.LocationID, W.[Name] As 'Location'
From ProjectOfficeLocation L Left Join ProjectOffice P On L.ProjectOfficeID = P.ProjectOfficeID
Left Join Location W On L.LocationID = W.LocationID
Left Join Region R On P.RegionID = R.RegionID
Table structures (some columns)
Region table
RegionID Name
ProjectOffice table
ProjectOfficeID Name RegionID
Location Table
LocationID Name
Country table
CountryID Name
Company table
CompanyID Name
ProjectCompany table (All rows)
ID ProjectOfficeID CompanyID
ProjectOfficeCountry table (All rows)
ID ProjectOfficeID CountryID
ProjectOfficeLocation table (All rows)
ID ProjectOfficeID LocationID
maybe something like this ?Select 'A' as [type], C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region'
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID Order By E.ProjectOfficeID
UNION ALL
Select 'B' as [type], P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country'
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID
UNION ALL
Select 'C' as [type], P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
W.LocationID, W.[Name] As 'Location'
From ProjectOfficeLocation L Left Join ProjectOffice P On L.ProjectOfficeID = P.ProjectOfficeID
Left Join Location W On L.LocationID = W.LocationID
Left Join Region R On P.RegionID = R.RegionID
Thanks carlop for replying,
If I did that then I could not differentiate between CompanyID and ProjectID or Company From Project Office or Location From Region, there should be a better way to do this...
Thanks.
|||I really don’t understand why you need in single SQL Statement. Are you trying to fetch those result in single batch (single hit to server).
If you don’t use the union all then you have to use the JOIN. It may lead your (desired) result set to duplicates (for region & country) and it is not helpful on Combobox binding.
|||ManiD,
Trying to get say data for Company, filtered by Region,Country, ProjectOffice, Company and Location, then data will be used to fill the combobox or dropdownlist control.
|||are you like to hit the db server once to get those data.
or
you need to have all the data in columns..?
|||ManiD,
Well, that is ideal to get all columns I needed and without duplicates. I have used several sql statements to achive same result, I wonder if it can be done using one single sql statement.
|||While I agree with the other posters that this is not a very good idea, you could probably use union to put all of the data in a single result:
Select C.CompanyID, C.[Name] As 'Company', P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID,
R.[Name] As 'Region', 'PURPOSE1' as purpose
From ProjectCompany E Left Join ProjectOffice P On E.ProjectOfficeID = P.ProjectOfficeID
Left Join Company C On E.CompanyID = C.CompanyID
Left Join Region R On P.RegionID = R.RegionID
UNION ALL
Select P.ProjectOfficeID, P.[Name] As 'Project Office', P.RegionID, R.[Name] As 'Region',
C.CountryID, C.[Name] As 'Country', 'PURPOSE2' as purpose
From ProjectOfficeCountry O Left Join ProjectOffice P On O.ProjectOfficeID = P.ProjectOfficeID
Left Join Country C On O.CountryID = C.CountryID
Left Join Region R On P.RegionID = R.RegionID
Note that you would also need to genericize the other names, like the id, the name, etc. I almost feel wrong in suggesting this, because it seems so much cleaner to make N result sets and get the data one set at a time (much cleaner and certainly eaiser to implement.)
|||Thanks for the reply Louis.
It seems there is no exact way getting all data needed in just one sql statement. I would stick to using multiple sql statements in getting the results.
Thanks.
I think the issue in this thread is closed.
Friday, February 10, 2012
Connect to SQL Server
It occurs something from strange.
I can reach Entreprise Manager, to visualize the tables, stored procedures...
But on the other hand I cannot install the Starter Kits "Connection Problem to the database".
Connections are done with SQL Server and Windows.
Do you have an idea?
Thanks.I think the starter kits assume yopu connect using Windows Authentication - meaning the _currently logged in account_ needs rights on the DB
if you're using mixed-mode as you suggest, then no wonder. see here :
http://rtfm.atrax.co.uk/infinitemonkeys/articles/miscellaneous/981.asp
but substitute your login account for installer access
Connect to SQL 2005 via Visual Studio application
mostly created on 2000 and attached. I have started creating a VS VB
application. I am able to use any and all the tables in the applications.
I
have updated individual tables.
I have published the appl and have installed it on a different PC. When I
do, I get this message: An error has occurred while establishing a
connection to the server. When connecting to SQL Server 2005 this failure
may be caused by the fact that under the default settings the SQL Server doe
s
not allow remote conncections.
I have previously configured the SQL server to allow remote TCP/IP
connections. However, I named the instance of the server when I created it.
My computer is BAA1 and the instance is BAA1\BAA2. I don't really want the
application to attach to my computer, but to the SQLEXPRESS (runtime?)
version of the database that goes with the application.
Can I buy a clue here? This is killing me.
Thanks in advance.
David BennerFor the first problem - connecting to the instance, run through my short
tutorial on connecting. It covers instance names, ports, firewalls, and the
protocols. It's in the Books Online tutorials, or at
http://msdn2.microsoft.com/en-us/library/ms345318(SQL.90).aspx
As for moving the database, after you are connected to BAA1\BAA2, run
sp_detach_db (http://msdn2.microsoft.com/en-us/library/ms188031.aspx) and
then on your SQL Express instance run CREATE DATABASE ... FOR ATTACH,
example E at http://msdn2.microsoft.com/en-us/library/ms176061.aspx
Rick Byham
MCDBA, MCSE, MCSA
Documentation Manager,
Microsoft, SQL Server Books Online
This posting is provided "as is" with
no warranties, and confers no rights.
"Benner" <Benner@.discussions.microsoft.com> wrote in message
news:0B6DB41B-68B3-4CDF-B48D-420DC1738DAB@.microsoft.com...
>I have created a SQL 2005 database with about 100 tables. It was actually
> mostly created on 2000 and attached. I have started creating a VS VB
> application. I am able to use any and all the tables in the applications.
> I
> have updated individual tables.
> I have published the appl and have installed it on a different PC. When I
> do, I get this message: An error has occurred while establishing a
> connection to the server. When connecting to SQL Server 2005 this failure
> may be caused by the fact that under the default settings the SQL Server
> does
> not allow remote conncections.
> I have previously configured the SQL server to allow remote TCP/IP
> connections. However, I named the instance of the server when I created
> it.
> My computer is BAA1 and the instance is BAA1\BAA2. I don't really want
> the
> application to attach to my computer, but to the SQLEXPRESS (runtime?)
> version of the database that goes with the application.
> Can I buy a clue here? This is killing me.
> Thanks in advance.
>
> --
> David Benner|||Rick:
Thanks for your reply.
I think I was not clear enough in describing my problem. I have no problem
connection to the database and using that database with a connection in VS
2005. I have updated the database with both the SQL Server Mgmt Studio and
with the application I have created. I am having trouble when I publish the
VS 2005 windows application and try to use it on another computer. I am not
trying to connect with the application back to my first or main computer, bu
t
expect the application to connect to a "runtime" version of the database on
the same computer as the application.
I don't have an instance called SQLEXPRESS. I am not sure if my
installation choices precluded that from installing or what. Can I create
the SQLEXPRESS instance or do I need it to do what I am describing?
David Benner
"Rick Byham [MS]" wrote:
> For the first problem - connecting to the instance, run through my short
> tutorial on connecting. It covers instance names, ports, firewalls, and th
e
> protocols. It's in the Books Online tutorials, or at
> http://msdn2.microsoft.com/en-us/library/ms345318(SQL.90).aspx
> As for moving the database, after you are connected to BAA1\BAA2, run
> sp_detach_db (http://msdn2.microsoft.com/en-us/library/ms188031.aspx) and
> then on your SQL Express instance run CREATE DATABASE ... FOR ATTACH,
> example E at http://msdn2.microsoft.com/en-us/library/ms176061.aspx
> Rick Byham
> MCDBA, MCSE, MCSA
> Documentation Manager,
> Microsoft, SQL Server Books Online
> This posting is provided "as is" with
> no warranties, and confers no rights.
> "Benner" <Benner@.discussions.microsoft.com> wrote in message
> news:0B6DB41B-68B3-4CDF-B48D-420DC1738DAB@.microsoft.com...
>
>|||You need to install SQL Express on the machine you want to run the
application on. When you do, it will create a SQLEXPRESS instance by
default. There's more information on User Instances here:
http://msdn.microsoft.com/sql/expre...expuserinst.asp
and more information on embedding express in your setup here:
http://msdn.microsoft.com/library/d...>
xCustApp.asp
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Benner" <Benner@.discussions.microsoft.com> wrote in message
news:A8DFB820-E29A-4266-A913-B58A5EEE3B25@.microsoft.com...[vbcol=seagreen]
> Rick:
> Thanks for your reply.
> I think I was not clear enough in describing my problem. I have no
> problem
> connection to the database and using that database with a connection in VS
> 2005. I have updated the database with both the SQL Server Mgmt Studio
> and
> with the application I have created. I am having trouble when I publish
> the
> VS 2005 windows application and try to use it on another computer. I am
> not
> trying to connect with the application back to my first or main computer,
> but
> expect the application to connect to a "runtime" version of the database
> on
> the same computer as the application.
> I don't have an instance called SQLEXPRESS. I am not sure if my
> installation choices precluded that from installing or what. Can I create
> the SQLEXPRESS instance or do I need it to do what I am describing?
>
> --
> David Benner
>
> "Rick Byham [MS]" wrote:
>