-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add Condition to ODBCDataSource #896
Comments
Yes, it is a problem. This is because MSI/WiX does not support conditions for ODBCDataSource element. Though you can have a condition associated with the parent component. Similar problem (but for RegValue element) is discussed here: regVal.AttributesDefinition += $";Component:Condition={yourCondition}"; |
I read that but i don't understand it well, i need more complete sample :) My code is like this: project = new ManagedProject("Setup",
new Dir($@"%ProgramFiles%\{myFolder}",
new File( binaries, @"Files\app.exe"
,new FileShortcut(binaries, "MyApp", $@"%ProgramMenu%\{myFolder}")
,new FileShortcut(binaries, "MyApp", @"%Desktop%")
)
,new DirFiles(binaries, @"Files\*.dll")
,new Dir("Documentation", new DirFiles(docs, @"Files\docs\*.*")
)
)
, new Property("INSTALLODBC", "no")
); Where to put ODBC , and how to add AttributesDefinition |
Have a look at the ODBC sample: Basically you will need: new ODBCDataSource(...)
{
AttributesDefinition = $";Component:Condition={yourCondition}";
} |
project = new ManagedProject("Setup",
new Dir($@"%ProgramFiles%\{myFolder}",
new File( binaries, @"Files\app.exe"
,new FileShortcut(binaries, "MyApp", $@"%ProgramMenu%\{myFolder}")
,new FileShortcut(binaries, "MyApp", @"%Desktop%")
)
,new DirFiles(binaries, @"Files\*.dll")
,new Dir("Documentation", new DirFiles(docs, @"Files\docs\*.*")
,new ODBCDataSource("[ODBC_DSN]", "[ODBC_DRIVER]", true, true,
new Property("Database", "[ODBC_DATABASE]"),
new Property("Server", "[ODBC_SERVER]")
)
{
AttributesDefinition = $";Component:Condition={new Condition("INSTALLODBC=\"yes\"")}"
}
)
)
, new Property("INSTALLODBC", "no")
); error CNDL0004: The Component element contains an unexpected attribute 'Condition'. |
my bad, component does not have a condition as an attribute but as an element. |
OK. this is how you can do it: project.WixSourceGenerated +=
doc => doc.FindFirst("ODBCDataSource")
.Parent("Component")
.AddElement(new XElement("Condition", "INSTALLODBC = \"yes\"")); I will have a look and provide a moreconvenient way of defining component conditions. |
This way is working . |
… to add Condition to ODBCDataSource #896 "
Done. In next release you will be able to use: new ODBCDataSource("DsnName", ...)
{
ComponentCondition = "INSTALLODBC = \"yes\""
} |
Any clue how to set ODBC( name , driver ,.. ) from session, they are strings ? if it is possible ofcourse... |
I am not sure it is possible. :( |
Np, so i will search other ways, like set registry keys, or post install app, that will make that kind of changes, or set odbc, and after install change name,driver , i wasn't familiar with limits of wix, and persisted, beg your pardon 👍 |
Way founded: [DllImport("ODBCCP32.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
static extern bool SQLConfigDataSourceW(IntPtr hwndParent, RequestFlags fRequest, string lpszDriver, string lpszAttributes);
enum RequestFlags : ushort
{
ODBC_ADD_DSN = 1,
ODBC_CONFIG_DSN = 2,
ODBC_REMOVE_DSN = 3,
ODBC_ADD_SYS_DSN = 4,
ODBC_CONFIG_SYS_DSN = 5,
ODBC_REMOVE_SYS_DSN = 6,
ODBC_REMOVE_DEFAULT_DSN = 7
};
public static bool AddDSN(string name, string dbn, string eng,string host="")
{
return SQLConfigDataSourceW(
(IntPtr)null, RequestFlags.ODBC_ADD_DSN
, Driver
, $"DSN={name}\0DBN={dbn}\0ENG={eng}\0LINKS=TCPIP(HOST={host})\0"
);
}
PS: lpszDriver, and lpszAttributes are for my case |
* - Issue #902: candle.exe : error CNDL0125 when building bootstrapper application from existing msi and add bootstrapper variable * Issue #862: I can't seem to get it working * Issue #900: Preserve messageType value for ExternalUI setup with Custom Actions * Merge pull request #899 from Q-Sharp/master * Added Condition Net48_Installed * Implemented/fixed `WixEntity.ComponentCondition`. Triggered by "How to add Condition to ODBCDataSource #896 " * Issue #894: LicenseBootstrapperApplication do not add payloads in case of rtf license * - Added `Process.StartElevated` extension method
Hi,
I have 2 scenarios , 1 - to pick from existing odbc source or 2 - to create new with 'new ODBCDataSource' , but i'm little noob, and still can't figure out how to implement, there is no Condition property for ODBCDataSource .
I am building ManagedProject.
The text was updated successfully, but these errors were encountered: