Before You Start
- Install a compatible SQL Server ODBC driver on the Windows machine running the game or editor.
- Know the server name, instance or address, database name, and login method.
- For Windows Authentication, make sure the Windows account running the game has access to the database.
- For username/password authentication, make sure SQL Server authentication is enabled on the server.
Blueprint Connection Steps
- Open the Blueprint that should own the database connection.
- Add the Microsoft SQL Server connection component from this product, or place the Microsoft SQL Server connection actor in the level and reference it.
- On your setup event, add
MakeMSSQLConnectionParams. - Fill
ServerandDatabase. - If using SQL login, fill
UsernameandPassword. - If using Windows Authentication, enable
bUseWindowsAuthentication. - Add ODBC settings such as encryption or certificate trust to
ExtraParamswhen needed. - Use
ConnectionStringOverrideonly when you need to provide the full ODBC string yourself. - Pass the params into
CreateConnection. - Bind
OnConnectionStatusChanged,OnConnectionInvalid,OnQuerySelectStatusChanged, andOnQueryUpdateStatusChanged.
Run a Select Query
- Wait until the connection reports success.
- Call
SelectDataFromQuery.
SELECT TOP 10 Id, DisplayName, Score
FROM dbo.Leaderboard
ORDER BY Score DESC;
- Use the select status event to check success or read the error message.
- Use the returned Blueprint rows/table to update UMG widgets or gameplay state.
Run an Insert, Update, or Delete
- Call
UpdateDataFromQueryfor statements that change data. - Bind
OnQueryUpdateStatusChangedto show progress and failures to the player or tool user.
UPDATE dbo.Leaderboard
SET Score = 3200
WHERE Id = 7;
Image and BLOB Workflow
This workflow is currently specific to Microsoft SQL Server. It is not enabled for PostgreSQL or MySQL in this package.
- Create a table column that can store binary image data, such as
VARBINARY(MAX). - Connect to SQL Server using the steps above.
- To upload an image from Blueprint, call
UpdateImageDatawith the file path or supported image input and the SQL update statement. - To load an image back into Unreal, call
SelectImageDataFromQuery. - Bind the image select status event and use the returned
Texture2Din UMG, materials, or runtime display actors.
SELECT TOP 1 PortraitImage
FROM dbo.PlayerPortraits
WHERE PlayerId = 7;
Microsoft SQL Notes
- The default generated connection path targets the SQL Server ODBC driver flow.
- Use
Trusted_Connectionthrough the Windows Authentication option instead of typing a Windows password into Blueprint. - Use
ConnectionStringOverridefor named instances, DSN paths, non-default drivers, or enterprise security strings. - Close the connection when your owning Blueprint is finished with it.