Showing posts with label words. Show all posts
Showing posts with label words. Show all posts

Friday, March 30, 2012

multi table or one big table?

I want to add my site a Hebrew English dictionary, I have a MS Access table with 55,000 words which I want to use.

I wondered if I should divide the table to little ones? (Lets say, to put each letter (a, b, c...) in different table. to check what the first word the user clicked and to get the data from this table. I just thought that 50,000 words is too much for each search, but I wonder if the code that I'll need to make the right table name will take longer?

Does 55000 rows is a big table? Should I worry about it or not?

Thanks...don't worry about it. 55000 rows isn't going to be too big of an issue. Just index the table based on any field you do a where clause on, and you'll be in good shape.|||Would you be interested in sharing your database of Hebrew words?

Monday, March 26, 2012

multi lingual where clause

I have a table with nvarchar column. In query analyzer when I run query with foreign language words that are already there in database it dose not return any rows

To test it I returned rows with Select * table. Then from result window I copy chinese characters and put it in SQL where clause in SQL analyzer .When I run query it dose not return results.

What could be the cause..its SQL 2k

found it add N infront of characters|||

As kyus94 indicated, to use UNICODE characters, including Chinese, you must preface the string with the character [ N ].

For example,

SELECT

Column1,

Column2,

etc

FROM MyTable

WHERE Column3 = N'ThisCouldBeChinese'

(Note the character No immediately before (no space) the string.)

sql

Wednesday, March 21, 2012

MSSQLService (MSDE) Not Re-Configured correctly

Hi all,

I have a question regarding restarting MS SQL Service under a different user, in other words, re-starting MSSQLService as a "Log on as" user instead of "Local System" account. By default MSSQLService starts as a local system account.

Now my problem is, that I install MSDE 2000 for my application. And I install it as a seperate instance with name "MyInstance". So after Install my service is called MSSQL$MyInstance.

so my process basically creates an NT user on the machine with administartors rights, stops the service, change the service configuration to my NT user account credentials and then starts it using scm. The whole process works fine on my machine running Win XP Pro v.2002 SP1. But it fails to work on Win XP Pro v2002 SP2.

on SP2 machine, service gets reconfigured because I can see the Log on as account being changed from Local System to MyNTUser. But when I try to start it every time error is "Log on failure". But when I go to service properties and change the Password to my NT users password service starts properly.

So i'm not sure what exactly is going on, because if reconfiguration process works for my machine, typically it should work on SP2 machine as well, as the notes on ChangeServiceConfig winapi method(requires Advapi32.dll) suggests that it will work for XP, NT and win 2002.

Does anyone has any idea why is that.

Code Snippets:

Create User:


DirectoryEntry AD = new DirectoryEntry("WinNT://" + machineName + ", computer");
DirectoryEntry newUser;
try {
newUser = AD.Children.Find(userName, "user");
DeleteNTUserAccount(userName);
newUser = AD.Children.Add(userName, "user");
}

catch (Exception) {
newUser = AD.Children.Add(userName, "user");
}
newUser.Invoke("Put", new object[] {"Description", userDescription});
newUser.Invoke("SetPassword", new object[] {userPWD});
newUser.CommitChanges();
DirectoryEntry group;
group = AD.Children.Find("Administrators", "group");
if (group != null)
group.Invoke("Add", new object[] {newUser.Path.ToString()});
group.Close();
newUser.Close();
AD.Close();


Code to Stop Service:


ServiceController sc;
TimeSpan timeout = new TimeSpan(0, 0, 60);
OperatingSystem os;
os = Environment.OSVersion;
if (os.Platform != PlatformID.Win32NT) {
txtInstallInfo.Text += "\r\n\tApplication is built only for NT, 2000, XP or Later";
this.Refresh();
retVal = false;
}
os = null;
sc = new ServiceController(serviceName);
if (sc.Status == ServiceControllerStatus.Running) {
if (sc.CanStop) {
txtInstallInfo.Text += "\r\n\tRestarting the " + serviceName + " service";
this.Refresh();
sc.Stop();
try {
sc.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
txtInstallInfo.Text += "\r\n\t" + serviceName + " service stopped successfully";
this.Refresh();
}

catch(TimeoutException) {
txtInstallInfo.Text += "\r\n\t" + serviceName + " service did not respond to the stop command in a timely fashion. Please Restart Installer at later time.";
this.Refresh();
retVal = false;
}
}
else {
txtInstallInfo.Text += "\r\n\t" + serviceName + " service cannot be stopped. Please Wait make sure no application is running.";
this.Refresh();
retVal = false;
}
}
else {
txtInstallInfo.Text += "\r\n\t" + serviceName + " service was not running.";
this.Refresh();
}
sc.Close();
sc = null;


Code to Re-Configure Service:


string UserName = "MyNTUser";
string UserPwd = "abc123";

int HandleToScm = OpenSCManager( null, null, ServiceControlAccessRights.AllAccess );

int HandleToSvc = OpenService( HandleToScm, ServiceName, ServiceSpecificAccessType.ChangeConfig );

if ( ChangeServiceConfig(
HandleToSvc,
ServiceControlType.OwnProcess,
ServiceStartType.AutoStart,
ServiceNoChange,
null,
null,
IntPtr.Zero,
null,
@.".\" + UserName,
UserPwd,
ServiceName ) ) {
CloseServiceHandle( HandleToSvc );
CloseServiceHandle( HandleToScm );
}


Code to Start Service:

scm -Action 1 -Service MSSQL$MyInstance -Silent 1 -SvcAccount .\MYNTUserAccount -SvcPwd MYNTAccountPassword

I've never seen this post before, yet it is dated May 2005. Bumping message...sql

Wednesday, March 7, 2012

MSSQL with one or more users

People, can u in few words explain to me which method is better: to use MSSQL own auth system - logins or to use one login for connection and make own auth subsystem?
Of course both methods works but i wanna know pluses and minuses of both methods.

RegardsIt is not a right question to ask it depends on level of security you want to achieve.

In case of a windows authentication:
If I, for example, logged in to my computer and left the room, anyone can stop by and get into the database. But on the other hand you dont have to do anything to get to the database. Users who got rights because they need to use some applications that connect to the database can easily get to the server itself and change any data they want on the back end. Some of them really think that they are very smart and know what they do. Especially when they try to update\delete with no WHERE condition or just do counts on millions of records (this can use up all server resources and stop the server from responding).

In case of a password protection:
If you have password protected login it is harder to get to the server you need to know a password. Also in very secure and protected environments (I work in one) password can be provided through a front end applications where they hashed before actually logging in to SQL Server. So in this case regular user doesnt even know his actual password to get to the server directly and each action of such user can be monitored and recorded.

So in first case it is less secure but much easier.
In second case it is opposite more secure but harder to get to the server.

It is the same as your mail box. Do you want your friends or relatives being able to get to your mail or you would put a password and will protect it from nosy readers.

Hope I answered your question.

Saturday, February 25, 2012

MSSQL Stored procedure Query using SELECT TOP

Is there a way to do a SELECT TOP # using a variable for the #?

In other words I'm doing a SELECT TOP 50* FROM DATATABLE

If I pass an @.value for the number

SELECT TOP @.value* FROM DATATABLE doesn't work

I am generating a random sampling of data and I want to allow the user to select the number of results they choose to have.

Thanks in advance.

I believe that is possible in 2005 and not in 2000. You can however use SET ROWCOUNT in 2000.

DECLARE @.tintSET @.t = 10SET ROWCOUNT @.tSELECT *FROM YourTableSET ROWCOUNT 0

|||

In 2005, the following works:

DECLARE @.t int
SET @.t = 20
SELECT TOP(@.t) * FROM yourTable