Oct 19, 2007

Connection Strings

Connection Strings

SQL Server 2005
SQL Native Client ODBC Driver

1. Standard security


Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername\SQLEXPRESS where you substitute Servername with the name of the computer where the SQL Server 2005 Express installation resides.

2. Attach a database file on connect to a local SQL Server Express instance


Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.

3. Attach a database file, located in the data directory, on connect to a local SQL Server Express instance


Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.


-----------------------------------------------------------------------------------------------

SQL Native Client OLE DB Provider

1. Standard security


Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername\SQLEXPRESS where you substitute Servername with the name of the computer where the SQL Server 2005 Express installation resides.

2. Trusted connection


Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;

Equivalent key-value pair: "Integrated Security=SSPI" equals "Trusted_Connection=yes"


3. Encrypt data sent over network


Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;Encrypt=yes;

4. Attach a database file on connect to a local SQL Server Express instance


Provider=SQLNCLI;Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.


5. Attach a database file, located in the data directory, on connect to a local SQL Server Express instance


Provider=SQLNCLI;Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.

------------------------------------------------------------------------------------------------

SqlConnection (.NET)

1. Standard Security


Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

Use serverName\instanceName as Data Source to connect to a specific SQL Server instance.
Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername\SQLEXPRESS where you substitute Servername with the name of the computer where the SQL Server 2005 Express installation resides.

2. Standard Security alternative syntax

This connection string produce the same result as the previous one. The reason to include it is to point out that some connection string keywords have many equivalents.

Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;



3. Trusted Connection


Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

4. Trusted Connection from a CE device

Often a Windows CE device is not authenticated and logged in to a domain. To use SSPI or trusted connection / authentication from a CE device, use this connection string.


Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;

Note that this will only work on a CE device.

5. Connect via an IP address


Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

DBMSSOCN=TCP/IP. This is how to use TCP/IP instead of Named Pipes. At the end of the Data Source is the port to use. 1433 is the default port for SQL Server.

6. Attach a database file on connect to a local SQL Server Express instance

Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;




Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.


7.Attach a database file, located in the data directory, on connect to a local SQL Server Express instance


Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.

8.Using an User Instance on a local SQL Server Express instance

The User Instance functionality creates a new SQL Server instance on the fly during connect. This works only on a local SQL Server 2005 instance and only when connecting using windows authentication over local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with limited administrative rights on the computer.


Data Source=.\SQLExpress;Integrated Security=true;AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;

To use the User Instance functionality you need to enable it on the SQL Server. This is done by executing the following command: sp_configure 'user instances enabled', '1'. To disable the functionality execute sp_configure 'user instances enabled', '0'.

Using CDO Email Encoding

public sub SendEmail(_
astrRecipientEmailAddress, _
astrCCEmailAddress, _
astrBCCEmailAddress, _
astrSenderEmailAddress, _
astrEmailSubject, _
astrEmailText)

'Dimension local variables
Dim objCDOMail


'Create Server Object
Set objCDOMail = Server.CreateObject("CDO.Message")

objCDOMail.From = astrSenderEmailAddress
objCDOMail.To = astrRecipientEmailAddress
objCDOMail.Subject = astrEmailSubject
objCDOMail.TextBody = astrEmailText

'this is the encoding part if you are using text as mail content
objCDOMail.BodyPart.Charset = "utf-8"
objCDOMail.TextBodyPart.Charset = "utf-8"

'this is the encoding part if you are using html as mail content
'create a proper html tag
'with Content-Type: text/html; charset=utf-8
objCDOMail.BodyPart.Charset = "utf-8"
objCDOMail.HtmlBodyPart.Charset = "utf-8"


'check whether to Copy or BCC this email
if len(astrCCEmailAddress) > 0 then
objCDOMail.CC = astrCCEmailAddress
end if
if len(astrBCCEmailAddress) > 0 then
objCDOMail.BCC = astrBCCEmailAddress
end if

objCDOMail.Send


end sub

MSSQL 2005 Backup and Restore SQL Syntax

RESTORE DB
---------------
RESTORE DATABASE myNewDb
FROM DISK = 'C:\Documents and Settings\Administrator\Desktop\family_backup.bak'
WITH MOVE 'myOldDb_Data' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\myNewDb.mdf',
MOVE 'myOldDb_Log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\myNewDb.ldf',
REPLACE

**Note:
If you are about to restore the old version sql2000 DB,
you can create a sql2005 db with the same name first,
change the DB Properties > Options > Capability Level > SQL2000 (80),
then you proceed with the above sql syntax


BACKUP DB
--------------
use [myNewDb]
BACKUP DATABASE [myNewDb] TO DISK = N'D:\Database Backup\myNewDb.bak'
WITH NOFORMAT, NOINIT, NAME = N'myNewDb-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO

Oct 18, 2007

Runtime Web.config / App.config Editing




Web.config configuration files and app.config project item files, which get converted to "ExecutableName.exe.config" at build time, both support the convenient appSettings section with its own read method in the System.Configuration.ConfigurationSettngs class. The appSettings section stores element name / value pairs in the format:

You can store as many of these elements as you want, read them out at runtime, and use the values in the application. If you have an item that contains multiple values and you would like to keep them together, you can store them as a single string, delimited with a pipe | or other symbol, read them out at runtime, and call the String.Split() method to parse them into a useable string array.

I often read out my appSetting values into a NameValueCollection at runtime, which provides one-shot acess to the entire collection in memory:

NameValueCollection mySettings = System.Configuration.ConfigurationSettings.AppSettings;
string connStr = mySettings["connString"];

But what about being able to change, add, and save appSettings items while that app is running in response to user input or other actions, instead of just reading them out? Nada, Zippo, Efes! You have to open the config file manually and add them by "hand". Well that kinda stinks, don't you think? So here's my take on a convenient little class that allows you to either modify, add or delete any appSettings element, in either your Executable, Console or ASP.NET web application at runtime, on the fly. Bear in mind of course, that if you modify a web.config on a running ASP.NET app, the ASP.NET worker process will recycle. Users currently using your app aren't exactly guaranteed to have a fun experience when this happens...

Original Source: http://www.eggheadcafe.com/articles/20030907.asp
By Peter A. Bromberg, Ph.D.

Oct 17, 2007

Failed to enable constraints













Did any one face this issue before ?

I had created odbc connection to mysql in .net 2.0 dataset.
Having issue on "fillby" transaction after i create a new select query.











In the front end page, having constraint issue too.
I had try to enable the dataset and set auto increment in the dataset to solve these issue on my local, but when upload to the server, the error happen again. :S

Any one have any idea ?




Oct 16, 2007

CAL3D Modeling Exportation

CAL3D Exportation

During FYP 3D Game , Novice Odyssey , I am lack of time to research Cal3D ,
thus, I am using MD2 to repalce Cal3D, Cal3D had been listed in my future list.
Who is interesting, may refer it:

1. create a box, modifier > editable mesh.
2. name your box head[0].
2. create bones for charactor and name your bones.
3. click your head[0], modifier > skin.
4. in skin modifier, add bones where the mesh covered.
5. click envelop, adjust the skin size.
6. click your box, utitlies > more > body paint.
7. send your box to body for uv map and texture.
8. in body paint, click your map and create a color of mapping.
8. adjust your uvmap vertex, paint your texture.
9. set your texture saiz as 128 x 128.
10. save your texture as tga file.
11. send back to 3d max
12. click m, material, beside your (standard) button, name your material.
13. material name should b head[0], body[1], leg[2]...
14. create your animation.
15. export your skeleton first.
16. click your mesh,export yuur mesh and choose your skeleton file as reference.
17. export your material, you wil see ur head[0] material.
18. export your animation.
19. create cfg files as below :

#
# cal3d model configuration file
#
# model: 2
#

scale=0.5

skeleton=m4.csf

animation=1.caf

mesh=m4_head.cmf
mesh=m4_body.cmf


material=1.crf
material=2.crf

20. create your batch file.
21. done.

How To Create MD2 ( Animated Model )

MD2 was my fyp game project 's modeling technique.
Today refresh all my notes in my Yahoo! notes and dig out some stuff to share over here.

How to create md2

1) in 3d max create the snow man, save snowman.max
2) convert into mesh or patch
3) in photoshop create texture 128 x 128
4) image> index color save as snowman.bmp
5) in 3dmax, press m, set only one material map
6) use body paint to paint it
7) in body paint,click ur object
8) click the mapping, scale down to seperate each mapping in diff place
9) paint it
10) in body paint save texture as bmp as 128x 128 (mus change later)
11) send back to 3dmax
12) qtip exporter, rename tris.pcx to snowman.pcx
13) use photoshop to change texture snowman.bmp put same name snowman.md2
14) check for the saiz 128x128 and the 8 bit color
15) u are done!!