|
If you are thinking conceptually, then the Visual Studio designer is probably the last thing you want to use.
I think your best approach is to create a class that manages the connection and have your forms use that class. Also, it would probably be a bad idea to have one form set the connection and have the other forms use it from the first form as the connection has nothing to do with the user interface and the data management functions should really be separated out into its own conceptual layer/tier within the application.
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|
|
Sadly I agree, although using the designer is one of my favorite tools in .NET.
|
|
|
|
|
i have MSSql Desktop engine installed and i m connecting to a database from ASP.net page. i m using oleDBconnection but when i Open() connection it gives me exception "Login failed 'MATRIX\ASPNET' " where Matrix is machin name. it is working well in Windows form but only givin problem in webforms , can any body tell wats wrong with it , i m using same connection string as for windows forms.
|
|
|
|
|
You're using Integrated Security in your connection string; that is, Windows Authentication. In this mode the database uses the credentials of the thread to authenticate the connection. Your Windows Forms application is running under your own user account, which is probably a member of the machine's Administrators group. The machine's Administrators group is granted login rights by default, and is a member of the System Administrators server role by default. In effect, your Windows user account has unlimited control over the database server.
By contrast, ASP.NET applications by default run under the ASPNET account on the local machine. This account is only a member of the Users group, which by default cannot log in to SQL Server.
You can allow the MATRIX\ASPNET user to log in using the following command (use osql to run the command):
EXEC sp_grantlogin 'MATRIX\ASPNET' The user can now log in to the database server, but won't be able to access any databases. Grant access to the user on the database by executing:
USE database
EXEC sp_grantdbaccess 'MATRIX\ASPNET' where database is the database that the user is granted access to.
This adds the user to the public database role. All users granted access to a database are members of this role. By default, this role has no permissions on objects created by the database owner. To grant permissions, you need to use the GRANT statement. It's recommended that you grant the public role only the permissions that are needed to perform the tasks. For example, if you wanted to allow all users to read data from the authors table, you would say
GRANT SELECT ON authors TO public Don't get confused between the REVOKE and DENY statements. DENY allows you to filter members from a group - for example I could use the statement
DENY SELECT ON authors TO Mike and SQL Server would then allow everyone except me to read from the authors table. REVOKE is used to undo an earlier GRANT or DENY operation.
If you want to give the ASPNET user complete control over the database - which is unadvisable - you can instead run
EXEC sp_addrolemember 'db_owner', 'MATRIX\ASPNET' I really don't advise this, though, as a mistake in the data access layer could corrupt your database. I recommend restricting the db_owner role to development and deployment use only.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
What libraries are needed to use the following code:
SQLDMOSvc_Running (SQL SERVER state).
When i use Set oSqlServer = New SQLServer, the (SQLSERVER) command is not recognised. So please supply a help.
|
|
|
|
|
Hello everyone,
I'm currently building a C# Windows Forms application, and have another machine on my network running MSDE 2000 as the database for my Windows App.
Its working fine except for one problem, MSDE keeps storing dates in US format (mm/dd/yy) instead of the format I want (dd/mm/yy). I'm passing in the dates to store as a string in the format dd/mm/yy in my SQL statements.
In the Regional Settings of the server computer, the locale is set to Enlish (New Zealand), and the short date format on the date tab is set to dd/MM/yy, yet it continues to use the wrong date format in MSDE. Do I need to somehow specify the locale that MSDE uses?
Any help would be greatly appreciated, this one is driving me nuts.
Many thanks, Hugo.
|
|
|
|
|
You can make osql format dates and times in your locale using the -R option. My installation of osql presents dates in ISO format (yyyy-MM-dd hh:mm:ss.nnn) when this option is not specified. I'm using the Latin1_General_CI_AS collation.
You should use the datetime or smalldatetime data types when handling date information. Always use parameters[^] to submit date/time information - indeed, any data - to the database.
In your application, you should be using the locale-sensitive format strings when using DateTime.ToString . You should check the value of System.Globalization.CultureInfo.CurrentCulture.Name - it should be en-NZ . If it isn't, check that the values in the Regional and Language Options[^] Control Panel applet (Regional Options[^] in Windows 2000) are correct.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thanks for your reply Mike,
I've checked the value of System.Globalization.CultureInfo.CurrentCulture.Name on both my development machine (Win XP) and the server machine (Win2k server) and they are both en-NZ. I am using smalldatetime data type to store the date.
Do I use the -R option on the osql command line after installtion, or is that something I need to specify for the installtion? I believe that just makes it use the client's locale settings?
Thanks for your help.
|
|
|
|
|
set dateformat dmy
However, If you use an intrinsic datetime data type from .Net, then you can use .Net's intrinsic culture support to format the date how you want.
Sql Server doesn't store a data in any particular culture. The date is if you like "rendered" according to various settings/defaults when it's displayed.
using System.Beer;
|
|
|
|
|
Thanks Jon,
Yes I was thinking that it was being stored in the database in a certain culture (i.e. US format), but what your saying is that its not stored in any particular format at all? It only gets converted to a "culture" when its displayed?
What I'm doing is reading dates directly from a text file (downloaded from tha bank each day) in the format "dd/mm/yy", and inserting that straight into the MSDE database through .NET. To view that data I created a MS Access project and I am just viewing the tables directly where I am inserting the data. If I insert 12/08/04, Access shows it in the tables as 08/12/04. Is that being stored incorrectly? Or is it just being displayed in the wrong format?
Appreciate your help,
Cheers, Hugo
|
|
|
|
|
How can I install a Database on the SQL SERVER 2000 programatically using VB.Net code?
With Regards
Rawad Eid
|
|
|
|
|
abo el ror wrote:
How can I install a Database on the SQL SERVER 2000 programatically using VB.Net code?
Do you mean how to add a database to the server, or actually install the server itself?
If you want to attach a database to the server using VB.NET then you can just create SqlCommand objects and use ExecuteNonQuery to run the appropriate SQL commands at the SQL Server. sp_attach_db[^] is probably the Stored Procedure you need. Remember that your SqlConnection to the database must use a user that is the sysadmin or dbcreator role.
Does this help?
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|
|
One thing you could do is use the SQLDMO library to encapsulate the objects in the server as types in your application.
~javier lozano
(blog)
|
|
|
|
|
Last week I asked for some help here[^] and didn't get a reply. I was at a client site most of the week and today I got back to some more testing and now know more and hopefully am asking the right question. If the SQL query assigned to a recordset instance refers to a table, then everything works, but if the SQL query assigned to the recordset is a view, then it doesn't work. Most baffling and I can't seem to dig up an answer in the help on this.
This works fine
CString strSQL("SELECT LANG_CODE, LANG_NAME FROM LANGUAGES_TABLE");
CRecordset rs(&db);
if ( rs.Open(AFX_DB_USE_DEFAULT_TYPE, strSQL) != TRUE )
{
return false;
}
while ( !rs.EOF() )
{
CString strLangCode;
CString strLangName;
rs.GetFieldValue("LANG_CODE", strLangCode);
rs.GetFieldValue("LANG_NAME", strLangName);
rs.MoveNext();
}
But when I change the SQL string to what I posted in my original post where the FROM clause refers to a view, then I get an exception thrown in the GetFieldValue call. The error is something about the Cursor State being illegal for fetching data. If anyone can help, I'd really be grateful. Thanks.
Chris Meech
I am Canadian. [heard in a local bar]
Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
rs.GetFieldValue turns (eventually) into a call to SQLGetData . The documentation for this function says that if you get state = 24000, one of the following is true (this is simply copied from the documentation):- (DM) The function was called without first calling SQLFetch or SQLFetchScroll to position the cursor on the row of data required.
- (DM) The StatementHandle was in an executed state, but no result set was associated with the StatementHandle.
- A cursor was open on the StatementHandle and SQLFetch or SQLFetchScroll had been called, but the cursor was positioned before the start of the result set or after the end of the result set.
It can't be the first, because CRecordset::Open calls MoveNext before returning. So either the database didn't return a resultset (which should have been caught by Open ) or no rows were returned - but this should have led to IsEOF returning FALSE .
Why this should work for a table but not a view I don't know. What ODBC driver are you using? For which database software?
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thanks for the comments, Mike. I'm back in my office again today and will be doing some more experimenting to see if I can figure it out. I think it will likely be more than just the fact that I'm querying a view. The particular view happens to contain about 4 function calls in it and that is likely playing a role in the failure. As far as the back end goes it's an Oracle 9i database and I've tried this with both the Oracle ODBC driver and the Microsoft ODBC driver with Oracle 9i client installed. I can run the SQL fine from the command line in SQL*Plus, but it is just from within a program that I've run into this stumbling block. Hopefully, I'll know more later. Thanks again.
Chris Meech
I am Canadian. [heard in a local bar]
Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
I hate it when things go this way, but this morning, I trashed my schema, re-built all the tables, views, functions and procedures. Then re-loaded data into the tables and my test and development programs are now working. So as odd as the problem was, it's disappeared after re-creating everything.
Thanks again for the comments, Mike.
Chris Meech
I am Canadian. [heard in a local bar]
Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
I was thinking the same thing. I will try it out the weekend and let you know. THanks for the help.
Brendan
|
|
|
|
|
Hi,
I have a category table in my SQL server database. I'm a bit confused and I'm hoping someone can help me. Each of my categories can have a sub category, and each sub category can have it's own sub category, and so on. I would like to know how to design my table(s) in such a way to link the various categories with its sub categories. I can create a subcategory table, but the only thing is I don't know how far the subcategories structure will go.
Can someone please advise me?
Brendan
|
|
|
|
|
You would use a self-referential join. In other words you join the table to itself.
Category
---------------------------------------
ID int not null
Name nvarchar(256) not null
ParentCategoryID int null
The ParentCategoryID is a foreignkey that refers to the ID column in Category. If it is null then it is a root category, if it has a parent then it is a sub-category. You can go as deep as you want (2billion+ subcategories deep if you need it)
This design also does away with the category and sub-category tables and replaces it with just one. Unless you need extra/different things in category and subcategory I'd stick with my design above, if category and sub-category require a different set of columns then the design will have to be with two tables.
Does this help?
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|
|
Have a problem with the Server.MapPath command.
This works on the local ServerA
Server.MapPath("\FSDIR\WORK\track.mdb");
If I want access it from ServerB, programm requires UNC path. This is UNC, isn't it ? He doesn't accept \\ServerB
Server.MapPath("\\ServerB\FSDIR\WORK\track.mdb");
Background :
I have a Connectionstring and need access to an external server. Is there another method to do this ? Has anybody an example for a connectionstring which handles external access ?
|
|
|
|
|
|
It's almost certainly a permissions problem.
IIS runs as an anonymous user, which probably won't have access to your share.
Try enabled NTLM (Integrated Windows Authentication) on your webserver, and then logging into your web application like that. IIS will then use your credentials, and it'll probably work.
using System.Beer;
|
|
|
|
|
Jon Hulatt wrote:
IIS runs as an anonymous user, which probably won't have access to your share.
IIS runs as a special user, not anonymous. The user name is different depending on the version of windows being used. In IIS you can set which user will be used when the end user is logged on as anonymous. This user can be configured as a domain user, by default it is a machine user.
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|
|
Is Microsoft SQL Desktop Engine comes along with the distribution of VS.net 2002? I really do not know how to identify such. After installing VS.net 2002, I do not get any SQL shortcut or executable for me to access it. Or I have to download it from Microsoft's Site?
And another thing, in case I got MSDE or Microsoft SQL server express 2005, is it possible to package it with local based application using it as its database? Just MSAccess where you do not need to install access to a local computer for your program to run?
Thank you in advance for your helps.
I just have to know
|
|
|
|