how to connect sql server database in C++ code? - c++

I have a project of C++ windows form. Now, I want to store the data in my SQL server database.
So, how can I connect my database from inside my C++ code and how to write an insert query?
I used the following code but it throws an exception that cannot open or cannot found the database.
SqlConnection^ con = gcnew SqlConnection();
int i = 0;
con->ConnectionString = "Data Source=122.179.151.229\EIEXPRESS;Initial Catalog=ICAST_IMS;Uid=developer;pwd=dev#12345";
con->Open();
SqlCommand^ com = gcnew SqlCommand();
com->Connection = con;
com->CommandText = "INSERT INTO image_analysis (nodule_count, nodularity) VALUES (final_nodule_count, 'final_nodularity')";
com->ExecuteNonQuery();

I think your problem it's your connection string, you include an "\" which is a special character, you need to try doing "\\" so the system recognize you're inserting an "\".
Hope this helps you!

Related

Cannot insert data in mysql database from windows form application in c++

I'm using VS-2017 and MySql 8.0 and I am trying to insert data from windows form application in c++; the project was run properly, but the query is not correct. I guess, when I insert data and click the save button I created, it says:
"you have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near " at line 1"
But I can insert data from the code manually (you can see the comment in the code which work), but i can not insert from the form! I done everything according to this video tutorial
Now how can I do that? My code is here:
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
String^ constring = L"datasource= 127.0.0.1; port= 3306;username=root;password=12712";
MySqlConnection^ conDataBase = gcnew MySqlConnection(constring);
MySqlCommand^ cmdDataBase = gcnew MySqlCommand("INSERT INTO `university`.`student` (`id`,`name`,`password`) values('"+this->id_txt->Text+"','"+this->name_txt->Text+"','"+this->password_txt->Text+"' ;", conDataBase);
//MySqlCommand^ cmdDataBase = gcnew MySqlCommand("INSERT INTO `university`.`student` (`id`, `name`, `password`) VALUES ('7', 'ah', '77'); ", conDataBase);

Fetch Data From MS SQL DB Using Ajax Auto Complete extender

I have an .aspx page that calls the .asmx web method to extract data from the MS SQL DB. I have tested the result without the connectionstring and it works.
I think my problem is with my connection string within the web.config, but i am not sure how to set it up. When i try to run the search with the SQL command i either get 500 server error or just nothing. Can someone please provide some advise?
partial web.config
<connectionStrings>
<add name="myConn" connectionString="Data Source=D:\\root\\Database\\; Initial Catalog=myData.mdb;Integrated Security=sspi;" />
</connectionStrings>
Web Method
Dim customers As List(Of String) = New List(Of String)
Dim conn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection
conn.ConnectionString = ConfigurationManager.ConnectionStrings("myConn").ConnectionString
Dim cmd As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand
cmd.CommandText = "SELECT col1, col2 from myTable where" &
" , like #SearchText + '%'"
cmd.Parameters.AddWithValue("#SearchText", prefixText)
cmd.Connection = conn
conn.Open()
Dim sdr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader
While sdr.Read
Dim item As String = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(sdr("col1").ToString, sdr("col2").ToString)
customers.Add(item)
End While
conn.Close()
Return customers
OK, since i was trying to connection to an Access database, I was suppose to use OleDB connection instead of SqlClient.
So I replaced all Sqlclient with OldDb and it promptly solved the problem. So it turns out, it is very important to know which database type you are connecting to before you try to make that connection.

coldfusion and sql server connection string

I am using coldfusion.
I have dedicated database server and shared webserver. Both are located on different server.
I do not have access of coldfusion administrator where I can create datasource.
I need help to create database connection in the code and needs to createDatasource Name.
I know this does not exactly answer your question, but may help a bit. Here I goes:
You can create a DSN less connection like example below. You can store the connection in Application.cfm/cfc:
<cfscript>
classLoader = createObject("java", "java.lang.Class");
classLoader.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dm = createObject("java","java.sql.DriverManager");
con = dm.getConnection("jdbc:odbc:DRIVER={MySQL ODBC 3.51 Driver}; SERVER=server; PORT=3306; DATABASE=database; USER=username; PASSWORD=password; OPTION=3;");
st = con.createStatement();
rs = st.ExecuteQuery("Select xyz FROM table");
q = createObject("java", "coldfusion.sql.QueryTable").init(rs);
//the query is stored in the variable q
</cfscript>
ps: reference http://www.hostmysite.com/support/mysql/coldfusionstring/

Search Informatica for text in SQL override

Is there a way to search all the mappings, sessions, etc. in Informatica for a text string contained within a SQL override?
For example, suppose I know a certain stored procedure (SP_FOO) is being called somewhere in an INFA process, but I don't know where exactly. Somewhere I think there is a Post SQL on a source or target calling it. Could I search all the sessions for Post SQL containing SP_FOO ? (Similar to what I could do with grep with source code.)
You can use Repository queries for querying REPO tables(if you have enough access) to get data related with all the mappings,transformations,sessions etc.
Please use the below link to get almost all kind of repo queries.Ur answers can be find in the below link.
https://uisapp2.iu.edu/confluence-prd/display/EDW/Querying+PowerCenter+data
select *--distinct sbj.SUBJECT_AREA,m.PARENT_MAPPING_NAME
from REP_SUBJECT sbj,REP_ALL_MAPPINGS m,REP_WIDGET_INST w,REP_WIDGET_ATTR wa
where sbj.SUBJECT_ID = m.SUBJECT_ID AND
m.MAPPING_ID = w.MAPPING_ID AND
w.WIDGET_ID = wa.WIDGET_ID
and sbj.SUBJECT_AREA in ('TLR','PPM_PNLST_WEB','PPM_CURRENCY','OLA','ODS','MMS','IT_METRIC','E_CONSENT','EDW','EDD','EDC','ABS')
and (UPPER(ATTR_VALUE) like '%PSA_CONTACT_EVENT%'
-- or UPPER(ATTR_VALUE) like '%PSA_MEMBER_CHARACTERISTIC%'
-- or UPPER(ATTR_VALUE) like '%PSA_REPORTING_HH_CHRSTC%'
-- or UPPER(ATTR_VALUE) like '%PSA_REPORTING_MEMBER_CHRSTC%'
)
--and m.PARENT_MAPPING_NAME like '%ARM%'
order by 1
Please let me know if you have any issues.
Another less scientific way to do this is to export the workflow(s) as XML and use a text editor to search through them for the stored procedure name.
If you have read access to the schema where the informatica repository resides, try this.
SELECT DISTINCT f.subj_name folder, e.mapping_name, object_type_name,
b.instance_name, a.attr_value
FROM opb_widget_attr a,
opb_widget_inst b,
opb_object_type c,
opb_attr d,
opb_mapping e,
opb_subject f
WHERE a.widget_id = b.widget_id
AND b.widget_type = c.object_type_id
AND ( object_type_name = 'Source Qualifier'
OR object_type_name LIKE '%Lookup%'
)
AND a.widget_id = b.widget_id
AND a.attr_id = d.attr_id
AND c.object_type_id = d.object_type_id
AND attr_name IN ('Sql Query')--, 'Lookup Sql Override')
AND b.mapping_id = e.mapping_id
AND e.subject_id = f.subj_id
AND a.attr_value is not null
--AND UPPER (a.attr_value) LIKE UPPER ('%currency%')
Yes. There is a small java based tool called Informatica Meta Query.
Using that tool, you can search for any information that is present in the Informatica meta data tables.
If you cannot find that tool, you can write queries directly in the Informatica Meta data tables to get the required information.
Adding few more lines to solution provided by Data Origin and Sandeep.
It is highly advised not to query repository tables directly. Rather, you can create synonyms or views and then query those objects to avoid any damage to rep tables.
In our dev/ prod environment application programmers are not granted any direct access to repo. tables.
As querying the Informatica database isn't the best idea, I would suggest you to export all the workflows in your folder into xml using Repository Manager. From Rep Mgr you can select all of them once and export them at once. Then write a java program to search the pattern from the xml's you have.
I have written a sample prog here, please modify it as per your requirement:
make a spec file with workflow names(specFileName).
main()
{
try {
File inFile = new File(specFileName);
BufferedReader reader = new BufferedReader(newFileReader(infile));
String tectToSearch = '<YourString>';
String currentLine;
while((currentLine = reader.readLine()) != null)
{
//trim newline when comparing with String
String trimmedLine = currentLine.trim();
if(currentline has the string pattern)
{
SOP(specFileName); //specfile name
}
}
reader.close();
}
catch(IOException ex)
{
System.out.println("Error reading to file '" + specFileName +"'");
}
}

Why does WebSharingAppDemo-CEProviderEndToEnd sample still need a client db connection after scope creation to perform sync

I'm researching a way to build an n-tierd sync solution. From the WebSharingAppDemo-CEProviderEndToEnd sample it seems almost feasable however for some reason, the app will only sync if the client has a live SQL db connection. Can some one explain what I'm missing and how to sync without exposing SQL to the internet?
The problem I'm experiencing is that when I provide a Relational sync provider that has an open SQL connection from the client, then it works fine but when I provide a Relational sync provider that has a closed but configured connection string, as in the example, I get an error from the WCF stating that the server did not receive the batch file. So what am I doing wrong?
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = hostName;
builder.IntegratedSecurity = true;
builder.InitialCatalog = "mydbname";
builder.ConnectTimeout = 1;
provider.Connection = new SqlConnection(builder.ToString());
// provider.Connection.Open(); **** un-commenting this causes the code to work**
//create anew scope description and add the appropriate tables to this scope
DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(SyncUtils.ScopeName);
//class to be used to provision the scope defined above
SqlSyncScopeProvisioning serverConfig = new SqlSyncScopeProvisioning();
....
The error I get occurs in this part of the WCF code:
public SyncSessionStatistics ApplyChanges(ConflictResolutionPolicy resolutionPolicy, ChangeBatch sourceChanges, object changeData)
{
Log("ProcessChangeBatch: {0}", this.peerProvider.Connection.ConnectionString);
DbSyncContext dataRetriever = changeData as DbSyncContext;
if (dataRetriever != null && dataRetriever.IsDataBatched)
{
string remotePeerId = dataRetriever.MadeWithKnowledge.ReplicaId.ToString();
//Data is batched. The client should have uploaded this file to us prior to calling ApplyChanges.
//So look for it.
//The Id would be the DbSyncContext.BatchFileName which is just the batch file name without the complete path
string localBatchFileName = null;
if (!this.batchIdToFileMapper.TryGetValue(dataRetriever.BatchFileName, out localBatchFileName))
{
//Service has not received this file. Throw exception
throw new FaultException<WebSyncFaultException>(new WebSyncFaultException("No batch file uploaded for id " + dataRetriever.BatchFileName, null));
}
dataRetriever.BatchFileName = localBatchFileName;
}
Any ideas?
For the Batch file not available issue, remove the IsOneWay=true setting from IRelationalSyncContract.UploadBatchFile. When the Batch file size is big, ApplyChanges will be called even before fully completing the previous UploadBatchfile.
// Replace
[OperationContract(IsOneWay = true)]
// with
[OperationContract]
void UploadBatchFile(string batchFileid, byte[] batchFile, string remotePeer1
I suppose it's simply a stupid example. It exposes "some" technique but assumes you have to arrange it in proper order by yourself.
http://msdn.microsoft.com/en-us/library/cc807255.aspx