|
Hi,
I'm a .net newbie & before this i have only worked with asp.
I'm trying to make a sample winforms intranet application using VS.net - c# and sql 2000 database.
The application works if executed on PC on which the sql-server is installed but does not seem to connect to the database when run on any other PC in the intranet.
Connection string used:
"data source=SUNNY;initial catalog=PROJ;password=sunny;persist security info=True;user id=softadmin;workstation id=192.168.1.2;packet size=4096";
Making the necessary changes in the connection string will do the trick OR does it required network socket programming...
Please provide guidance. Any url links to related articles will be of great help. Thanx in advance.
Sunny
|
|
|
|
|
Changing the connectionstring should suffice. The network plumbing has been done for you in the SQL Server OLEDB/ODBC drivers.
A quick checklist:
1. Check that the SQL Server is set up to use mixed mode authentication. (Both NT and SQL logins, NOT NT ONLY...)
2. Check all params in the connectionstring
3. Check you network infrastucture.
|
|
|
|
|
Hi Arjan, Thanx 4 clarifying the point - i've gone thru 2 books and done lots of browsing but could not get the answer whether i needed to do network programming in this scenario. I should have posted my problem on this forum - would have saved me lots of time.
AS PER YOUR CHECKLIST:
1) I checked and found that the authentication is mixed mode.
2) The params all seem to be correct, the code was generated by VS.Net IDE.
The only point i'm not clear about is whether "workstation id=192.168.1.2" is what is required to tell the program the location of the database. The database is on PC with ip address 192.168.1.2
The programs functions satisfactorily on the PC on which the database is located but returns an Alert message "Invalid User" to be displayed after validation if username & password is incorrect.
THE CONNECTION STRING USED:
"data source=SUNNY;initial catalog=PROJ;password=sunny;persist security info=True;user id=softadmin;workstation id=192.168.1.2;packet size=4096";
3) Network Infrastructure seems all ok - I'm able to access each one of the comps from the other.
Sunny.
|
|
|
|
|
Try changing the connection string to
"Data source=SUNNY;initial catalog=PROJ;user id=softadmin;password=sunny;"
accept the defaults for persisting security info (FALSE), packet size. I am not familiar with using 'workstation id' in a connection string. The data source should be the NODE Name where the server is located (or the SQL server instance name in the event you have multiple instances on the same box ( not likely with MSDE, but allowed with full SQL version). In any event, SQL server network library should resolve the targe host. You can also use the IP as the value for data source. Make sure you can ping the server node from the client. Try adding "Network library=Dbmssocn;" to the connection string to force the use of the TCPIP network library
also make sure you have added that user and login to the SQL database (sp_adduser, sp_grantdbaccess - the latter to the specific database, the former to the server in general, not all users get automatic access to all databases).
Make sure the user has access to the tables,etc in the data base (grant Select,insert,update,delete to 'user' on 'table')
you might want to download the SQl Server Books Online[^] for a complete reference to SQL 2000...(I don't think this comes with MSDE, but it is free, and indespensable if you are going to work with SQL 2000).
Another good reference for connection strings is here[^]
This is gor ADO,OLEDB,and ODBC connections, but the ADO/OLEDB strings for SQL server work just fine (just leave out the "Provider=sqloledb" part).
Genius may have its limitations, but stupidity is not thus handicapped. - Elbert Hubbard
|
|
|
|
|
Thank u Rob. Thanx Arjan. You guys were a great help. Finally i was able to solve the problem.
I used Try-Catch while connecting to the database & it returned the following error:
"The .net data sql provider (system.data.sqlclinet) requires microsoft data access components (mdac) version 2.6 or later"
So I downloaded MDAC 2.8 from the microsoft website and the problem was solved.
Expect to see a lot of posts from me on this forum. I'll be needing ur expert advise from time to time. Couldn't have solved this problem without your guidance. Thanx again.
Sunny.
|
|
|
|
|
|
Does any1 know how can I convert a database from SQL Server 2000 to SQ Server 7.0
Database is very simple and this shouldn't be very difficult I imagine.
Or am I wrong?...
Love is the law, love under will.
|
|
|
|
|
Easiest way is to use DTS.
Select the 2K database, and transfer all the objects. You might need to set the checkbox that suppresses non-2K specific features.
Steve S
|
|
|
|
|
You wrote: "You might need to set the checkbox that suppresses non-2K specific features."
BUT I don't find this feature. Please where is it. If I click Advanced there is no NON 2k specific features. I found this only in "Generate SQL Script"
Love is the law, love under will.
|
|
|
|
|
Then don't use that feature
I vaguely remembered it from the generate SQL script. I think DTS will correctly compensate for anything that is SQLS2000 specific when it does the transfer.
We've done just this here, and it seems to work just fine. There are various optional bits, like transferring permissions etc that you can tinker with.
Steve S
|
|
|
|
|
Backup the SQL 7 DB and restore it to your SQL 2000 Server...
|
|
|
|
|
its not from 7-> 2000
I meant 2000 -> 7.0
Love is the law, love under will.
|
|
|
|
|
Sorry. My wrong...
Then I'd go for eiter Steve S's solution, or use Enterprise Manager to create the scripts...
Just be sure to set up SQL logins correcty first, and doublecheck that indexes and foreign keys will be created...
|
|
|
|
|
How to check whether a table exist not in the database ?
In oracle can use : Select Table_Name from All_Tables
what about in MSAccess and MS SQL Server ?
|
|
|
|
|
SQL Server:
SELECT * FROM information_schema.tables WHERe table_type = 'BASE TABLE'
Access: dunno...
|
|
|
|
|
I use this query
if exists(select name from sysdatabases where name='DatabaseName') begin
-- do some stuffs here
end
cheers
|
|
|
|
|
He asked about tables, not databases, so it would be sysobjects where name = 'Foo' and type = 'U', but accessing the sysdatabases/sysobjects/etc tables directly has been depreciated since SQL7. You should use either the metadata functions or the INFORMATION_SCHEMA views instead.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Arjan's answer is also correct, but I prefer:
if objectproperty(object_id('YourTableName'), 'IsTable') = 1 begin
-- do something
end
--
-Blake (com/bcdev/blake)
|
|
|
|
|
I apologised for the mistake. I don't know why 'database' was in my mind then. I also prefer the object_property(object_id()) construct.
Tnx for the correction.
|
|
|
|
|
I'm writting a program that will act as a front end to an access database (although I hope to have it handle other databases eventually) and I've manage to retrive my data using the adapter class to fill a dataset and I've managed to bind the dataset to my form. Now, binding to the textboxes was easy (actually it was quite painful, but now it's easy because I know how to do it), but I'm not sure how to cope with checkboxes that should be set according to a boolean field in the access database. Can anybody tell me the correct way to do this? Also, I haven't even looked at the combo boxes yet, so if anybody has some insight on that they feel like sharing I'd appreciate it.
Cheers
|
|
|
|
|
Never mind. It actually was working all along, the problem was with the data itself.
|
|
|
|
|
_ConnectionPtr m_pConnection;
what does the above statement mean..?
i have to use the above mentioned in my program to get the data from my database..
can some one plzzz explain me on what it actually means...
and i've attached the code also with this query!
does the attached code really help me in making a connection with my database and getting the data from it....???
here's the code i had mentioned:
#include <windows.h>
#include <initguid.h> // Include only once in your application
#include "adoid.h" // ADO GUID's
#include "adoint.h" // ADO Classes, enums, etc.
#include <windows.h>
//#import <msado15.dll> rename("EOF", "adoEOF")
/*In this example, I am using mcb.krz database which is an access database.
The table i do have in example is 'Access' that has two fields,
i.e., Name and HTML, both are Text type fields. Microsoft.Jet.OLEDB.3.51 is OLE_DB provider
for MS Access. To use ADO, you must have OLE-DB provider for that database. */
// Create a Connection object and open it with mcb.krz, an access database
_ConnectionPtr m_pConnection;
BOOL m_bIsConnectionOpen;
// Create an instance of _Connection
HRESULT hr ;
hr = m_pConnection.CreateInstance(__uuidof( Connection) );
if (SUCCEEDED(hr))
{
//Open a connection where database is access database : "d:\mcb.krz"
hr = m_pConnection->Open( _bstr_t(L"Provider=Microsoft.Jet.OLEDB.3.51;
Data Source=d:\\mcb.krz;"), _bstr_t(L""), _bstr_t(L""), adModeUnknown ) ;
//If database opened successfully then set IsConnectionOpen to TRUE
if (SUCCEEDED(hr))
{
m_bIsConnectionOpen = TRUE;
}
}
_RecordsetPtr pRecordset;
// Here I take data from a table called KRUSE1 which has two fields a0, and a1 of TEXT type
_bstr_t bstrQuery("SELECT * FROM Kruse1");
_variant_t vRecsAffected(0L);
try
{
pRecordset = m_pConnection->Execute(bstrQuery, &vRecsAffected,adOptionUnspecified);
if ( !pRecordset->GetadoEOF())
{
int i = 0;
_variant_t vFirstName;
_variant_t vLastName;
while ( !pRecordset->GetadoEOF() )
{
vFirstName = pRecordset->GetCollect(L"a0") ;
vLastName = pRecordset->GetCollect(L"a1") ;
// now you got vFirstName and vLastName values and do whatever u want.
i++;
pRecordset->MoveNext();
}
}
pRecordset->Close();
}
catch( _com_error &e)
{
// get info from _com_error
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
TRACE("%s", e.ErrorMessage());
}
catch(...)
{
TRACE("*** UNHANDELED EXCEPTION ***");
}
ranjani
|
|
|
|
|
ranjjj wrote:
_ConnectionPtr m_pConnection;
That is just declaring an ADO Connection object variable.
ConnectionPtr is a smart pointer for the ADO Connection object interface.
ranjjj wrote:
does the attached code really help me in making a connection with my database and getting the data from it....???
At a quick glance the code seems fine. It should open a connection to an Access database and read all the records from it.
Michael
'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
|
|
|
|
|
_ConnectionPtr m_pConnection;
when executing the file..
i get the error as:
error c2501:_ConnectionPtr missing storage class or type specifier
and
missing identifier ; before 'm_pConnection'
ranjani
|
|
|
|
|
Skip the includes and use the import instead to get the types and remember that the namespace is named ADODB.
|
|
|
|